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

26 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-15 05:15 +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 core as _core 

26from . import detection as _detection 

27from . import population as _population 

28 

29 

30class Application( __.appcore_cli.Application ): 

31 ''' Agents configuration management CLI. ''' 

32 

33 version: __.typx.Annotated[ 

34 bool, 

35 __.tyro.conf.arg( 

36 help = "Print package version and exit." ), 

37 __.tyro.conf.FlagCreatePairsOff, 

38 ] = False 

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

40 default_factory = _core.DisplayOptions ) 

41 command: __.typx.Union[ 

42 __.typx.Annotated[ 

43 _detection.DetectCommand, 

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

45 ], 

46 __.typx.Annotated[ 

47 _population.GenerateCommand, 

48 __.tyro.conf.subcommand( 'generate', prefix_name = False ), 

49 ], 

50 __.typx.Annotated[ 

51 _population.PopulateCommand, 

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

53 ], 

54 ] = __.dcls.field( default_factory = _detection.DetectCommand ) 

55 

56 async def __call__( self ) -> None: 

57 ''' Reports version or prepares session and executes command. ''' 

58 if self.version: 58 ↛ 62line 58 didn't jump to line 62 because the condition on line 58 was always true

59 from agentsmgr import __version__ 

60 print( '{0} {1}'.format( __.package_name, __version__ ) ) 

61 return 

62 await super( ).__call__( ) 

63 

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

65 await self.command( auxdata ) 

66 

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

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

69 nomargs = { 

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

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

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

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

74 

75 

76def execute( ) -> None: 

77 ''' Entrypoint for CLI execution. ''' 

78 config = ( 

79 __.tyro.conf.EnumChoicesFromValues, 

80 __.tyro.conf.HelptextFromCommentsOff, 

81 ) 

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

83 except SystemExit: raise 

84 except BaseException: 

85 # TODO: Log exception. 

86 raise SystemExit( 1 ) from None