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

19 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-23 02:37 +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.PopulateCommand, 

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

43 ], 

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

45 

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

47 await self.command( auxdata ) 

48 

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

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

51 nomargs = { 

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

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

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

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

56 

57 

58def execute( ) -> None: 

59 ''' Entrypoint for CLI execution. ''' 

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

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

62 except SystemExit: raise 

63 except BaseException: 

64 # TODO: Log exception. 

65 raise SystemExit( 1 ) from None