Coverage for sources/agentsmgr/cli.py: 50%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-13 00:43 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Command-line interface. ''' 

22 

23 

24from . import __ 

25from . import commands as _commands 

26from . import core as _core 

27 

28 

29class Application( __.appcore_cli.Application ): 

30 ''' Agent configuration management CLI. ''' 

31 

32 display: _core.DisplayOptions = __.dcls.field( 

33 default_factory = _core.DisplayOptions ) 

34 command: __.typx.Union[ 

35 __.typx.Annotated[ 

36 _commands.DetectCommand, 

37 __.tyro.conf.subcommand( 'detect', prefix_name = False ), 

38 ], 

39 __.typx.Annotated[ 

40 _commands.PopulateCommand, 

41 __.tyro.conf.subcommand( 'populate', prefix_name = False ), 

42 ], 

43 __.typx.Annotated[ 

44 _commands.ValidateCommand, 

45 __.tyro.conf.subcommand( 'validate', prefix_name = False ), 

46 ], 

47 ] = __.dcls.field( default_factory = _commands.DetectCommand ) 

48 

49 async def execute( self, auxdata: _core.Globals ) -> None: # pyright: ignore[reportIncompatibleMethodOverride] 

50 ''' Executes the specified command. ''' 

51 await self.command( auxdata ) 

52 

53 async def prepare( self, exits: __.ctxl.AsyncExitStack ) -> _core.Globals: 

54 ''' Prepares agentsmgr-specific global state with display options. ''' 

55 auxdata_base = await super( ).prepare( exits ) 

56 nomargs = { 

57 field.name: getattr( auxdata_base, field.name ) 

58 for field in __.dcls.fields( auxdata_base ) 

59 if not field.name.startswith( '_' ) } 

60 return _core.Globals( display = self.display, **nomargs ) 

61 

62 

63def execute( ) -> None: 

64 ''' Entrypoint for CLI execution. ''' 

65 config = ( __.tyro.conf.HelptextFromCommentsOff, ) 

66 try: __.asyncio.run( __.tyro.cli( Application, config = config )( ) ) 

67 except SystemExit: raise 

68 except BaseException: 

69 # TODO: Log exception. 

70 raise SystemExit( 1 ) from None