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

19 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-08 06:57 +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 display: _core.DisplayOptions = __.dcls.field( 

34 default_factory = _core.DisplayOptions ) 

35 command: __.typx.Union[ 

36 __.typx.Annotated[ 

37 _detection.DetectCommand, 

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

39 ], 

40 __.typx.Annotated[ 

41 _population.GenerateCommand, 

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

43 ], 

44 __.typx.Annotated[ 

45 _population.PopulateCommand, 

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

47 ], 

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

49 

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

51 await self.command( auxdata ) 

52 

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

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

55 nomargs = { 

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

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

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

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

60 

61 

62def execute( ) -> None: 

63 ''' Entrypoint for CLI execution. ''' 

64 config = ( 

65 __.tyro.conf.EnumChoicesFromValues, 

66 __.tyro.conf.HelptextFromCommentsOff, 

67 ) 

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

69 except SystemExit: raise 

70 except BaseException: 

71 # TODO: Log exception. 

72 raise SystemExit( 1 ) from None