Coverage for sources / mimeogram / cli.py: 50%
38 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-18 17:27 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-18 17:27 +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 apply as _apply
26from . import create as _create
27from . import interfaces as _interfaces
28from . import prompt as _prompt
31_scribe = __.produce_scribe( __name__ )
34class VersionCommand(
35 _interfaces.CliCommand,
36 decorators = ( __.standard_tyro_class, ),
37):
38 ''' Prints version information. '''
40 async def __call__(
41 self, auxdata: __.appcore.state.Globals
42 ) -> None:
43 ''' Executes command to print version information. '''
44 from . import __version__
45 print( f"{__package__} {__version__}" )
46 raise SystemExit( 0 )
48 def provide_configuration_edits(
49 self,
50 ) -> __.appcore.dictedits.Edits:
51 ''' Provides edits against configuration from options. '''
52 return ( )
55_application_default = __.appcore.application.Information( name = 'mimeogram' )
56_inscription_mode_default = (
57 __.appcore_cli.InscriptionControl(
58 presentation = __.appcore.inscription.Presentations.Rich,
59 )
60)
63class Cli(
64 __.immut.DataclassObject,
65 decorators = ( __.simple_tyro_class, ),
66):
67 ''' Mimeogram: hierarchical data exchange between humans and LLMs. '''
69 application: __.appcore.application.Information = (
70 __.dcls.field( default_factory = lambda: _application_default ) )
71 configfile: __.typx.Optional[ str ] = None
72 # display: ConsoleDisplay
73 inscription: __.appcore_cli.InscriptionControl = (
74 __.dcls.field( default_factory = lambda: _inscription_mode_default ) )
75 command: __.typx.Union[
76 __.typx.Annotated[
77 _create.Command,
78 __.tyro.conf.subcommand(
79 'create', prefix_name = False ),
80 ],
81 __.typx.Annotated[
82 _apply.Command,
83 __.tyro.conf.subcommand(
84 'apply', prefix_name = False ),
85 ],
86 __.typx.Annotated[
87 _prompt.Command,
88 __.tyro.conf.subcommand(
89 'provide-prompt', prefix_name = False ),
90 ],
91 __.typx.Annotated[
92 VersionCommand,
93 __.tyro.conf.subcommand(
94 'version', prefix_name = False ),
95 ],
96 ]
98 async def __call__( self ):
99 ''' Invokes command after library preparation. '''
100 async with __.ctxl.AsyncExitStack( ) as exits:
101 nomargs = self.prepare_invocation_args( exits )
102 auxdata = await __.appcore.prepare( exits = exits, **nomargs )
103 await self.command( auxdata = auxdata )
104 # await self.command( auxdata = auxdata, display = self.display )
106 def prepare_invocation_args(
107 self,
108 exits: __.ctxl.AsyncExitStack,
109 ) -> __.cabc.Mapping[ str, __.typx.Any ]:
110 ''' Prepares arguments for initial configuration. '''
111 configedits: __.appcore.dictedits.Edits = (
112 self.command.provide_configuration_edits( ) )
113 args: dict[ str, __.typx.Any ] = dict(
114 application = self.application,
115 configedits = configedits,
116 environment = True,
117 inscription = self.inscription.as_control( exits ),
118 )
119 if self.configfile: args[ 'configfile' ] = self.configfile
120 return args
123def execute( ):
124 ''' Entrypoint for CLI execution. '''
125 from asyncio import run
126 config = (
127 __.tyro.conf.EnumChoicesFromValues,
128 __.tyro.conf.HelptextFromCommentsOff,
129 )
130 # default = Cli(
131 # application = _application.Information( ),
132 # display = ConsoleDisplay( ),
133 # inscription = _inscription.Control( mode = _inscription.Modes.Rich ),
134 # command = InspectCommand( ),
135 # )
136 try: run( __.tyro.cli( Cli, config = config )( ) )
137 except SystemExit: raise
138 except BaseException:
139 _scribe.exception(
140 "Program terminated from uncaught exception. "
141 "Please file a bug report." )
142 raise SystemExit( 1 ) from None