Coverage for sources/agentsmgr/cli.py: 94%
29 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-27 17:58 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-27 17:58 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
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#============================================================================#
21''' Command-line interface. '''
24from . import __
25from . import core as _core
26from . import detection as _detection
27from . import exceptions as _exceptions
28from . import population as _population
31class Application( __.appcore_cli.Application ):
32 ''' Agents configuration management CLI. '''
34 version: __.typx.Annotated[
35 bool,
36 __.tyro.conf.arg(
37 help = "Print package version and exit." ),
38 __.tyro.conf.FlagCreatePairsOff,
39 ] = False
40 display: _core.DisplayOptions = __.dcls.field(
41 default_factory = _core.DisplayOptions )
42 command: __.typx.Union[
43 __.typx.Annotated[
44 _detection.DetectCommand,
45 __.tyro.conf.subcommand( 'detect', prefix_name = False ),
46 ],
47 __.typx.Annotated[
48 _population.GenerateCommand,
49 __.tyro.conf.subcommand( 'generate', prefix_name = False ),
50 ],
51 __.typx.Annotated[
52 _population.PopulateCommand,
53 __.tyro.conf.subcommand( 'populate', prefix_name = False ),
54 ],
55 ] = __.dcls.field( default_factory = _detection.DetectCommand )
57 async def __call__( self ) -> None:
58 ''' Reports version or prepares session and executes command. '''
59 if self.version: 59 ↛ 63line 59 didn't jump to line 63 because the condition on line 59 was always true
60 from agentsmgr import __version__
61 print( '{0} {1}'.format( __.package_name, __version__ ) )
62 return
63 await super( ).__call__( )
65 async def execute( self, auxdata: _core.Globals ) -> None: # pyright: ignore[reportIncompatibleMethodOverride]
66 await self.command( auxdata )
68 async def prepare( self, exits: __.ctxl.AsyncExitStack ) -> _core.Globals:
69 auxdata_base = await super( ).prepare( exits )
70 nomargs = {
71 field.name: getattr( auxdata_base, field.name )
72 for field in __.dcls.fields( auxdata_base )
73 if not field.name.startswith( '_' ) }
74 return _core.Globals( display = self.display, **nomargs )
77def execute( ) -> None:
78 ''' Entrypoint for CLI execution. '''
79 config = (
80 __.tyro.conf.EnumChoicesFromValues,
81 __.tyro.conf.HelptextFromCommentsOff,
82 )
83 try: __.asyncio.run( __.tyro.cli( Application, config = config )( ) )
84 except SystemExit: raise
85 except BaseException as exception:
86 for line in (
87 _exceptions.UnexpectedError( exception ).render_as_markdown( )
88 ):
89 print( line, file = __.sys.stderr )
90 raise SystemExit( 1 ) from None