communex.cli.root
1from typing import Annotated, Optional 2 3import typer 4 5from communex import __version__ 6 7from ._common import ExtraCtxData 8from .balance import balance_app 9from .key import key_app 10from .misc import misc_app 11from .module import module_app 12from .network import network_app 13from .subnet import subnet_app 14 15app = typer.Typer() 16 17app.add_typer(key_app, name="key", help="Key operations") 18app.add_typer(balance_app, name="balance", help="Balance operations") 19app.add_typer(misc_app, name="misc", help="Other operations") 20app.add_typer(module_app, name="module", help="Module operations") 21app.add_typer(network_app, name="network", help="Network operations") 22app.add_typer(subnet_app, name="subnet", help="Subnet operations") 23 24 25def _version_callback(value: bool): 26 if value: 27 print(f"CommuneX {__version__}") 28 raise typer.Exit() 29 30 31def flag_option( 32 flag: str, 33 flag_envvar: str, 34 flag_help: str, 35 flag_short: str | None = None, 36): 37 flag_long = f"--{flag}" 38 flag_short = f"-{flag[0]}" if flag_short is None else f"-{flag_short}" 39 return typer.Option( 40 flag_long, flag_short, is_flag=True, envvar=flag_envvar, help=flag_help 41 ) 42 43 44@app.callback() 45def main( 46 ctx: typer.Context, 47 json: Annotated[ 48 bool, 49 flag_option( 50 "json", "COMX_OUTPUT_JSON", "Output machine-readable JSON." 51 ), 52 ] = False, 53 testnet: Annotated[ 54 bool, 55 flag_option("testnet", "COMX_USE_TESTNET", "Use testnet endpoints."), 56 ] = False, 57 yes_to_all: Annotated[ 58 bool, 59 flag_option( 60 "yes", "COMX_YES_TO_ALL", "Say yes to all confirmation inputs." 61 ), 62 ] = False, 63 version: Annotated[ 64 Optional[bool], typer.Option(callback=_version_callback) 65 ] = None, 66): 67 """ 68 CommuneX CLI {version} 69 70 This command line interface is under development and subject to change. 71 """ 72 # Pass the extra context data to the subcommands. 73 ctx.obj = ExtraCtxData( 74 output_json=json, use_testnet=testnet, yes_to_all=yes_to_all 75 ) 76 77 78if main.__doc__ is not None: 79 main.__doc__ = main.__doc__.format(version=__version__)
app =
<typer.main.Typer object>
def
flag_option( flag: str, flag_envvar: str, flag_help: str, flag_short: str | None = None):
32def flag_option( 33 flag: str, 34 flag_envvar: str, 35 flag_help: str, 36 flag_short: str | None = None, 37): 38 flag_long = f"--{flag}" 39 flag_short = f"-{flag[0]}" if flag_short is None else f"-{flag_short}" 40 return typer.Option( 41 flag_long, flag_short, is_flag=True, envvar=flag_envvar, help=flag_help 42 )
@app.callback()
def
main( ctx: typer.models.Context, json: typing.Annotated[bool, <typer.models.OptionInfo object>] = False, testnet: typing.Annotated[bool, <typer.models.OptionInfo object>] = False, yes_to_all: typing.Annotated[bool, <typer.models.OptionInfo object>] = False, version: Annotated[Optional[bool], <typer.models.OptionInfo object>] = None):
45@app.callback() 46def main( 47 ctx: typer.Context, 48 json: Annotated[ 49 bool, 50 flag_option( 51 "json", "COMX_OUTPUT_JSON", "Output machine-readable JSON." 52 ), 53 ] = False, 54 testnet: Annotated[ 55 bool, 56 flag_option("testnet", "COMX_USE_TESTNET", "Use testnet endpoints."), 57 ] = False, 58 yes_to_all: Annotated[ 59 bool, 60 flag_option( 61 "yes", "COMX_YES_TO_ALL", "Say yes to all confirmation inputs." 62 ), 63 ] = False, 64 version: Annotated[ 65 Optional[bool], typer.Option(callback=_version_callback) 66 ] = None, 67): 68 """ 69 CommuneX CLI {version} 70 71 This command line interface is under development and subject to change. 72 """ 73 # Pass the extra context data to the subcommands. 74 ctx.obj = ExtraCtxData( 75 output_json=json, use_testnet=testnet, yes_to_all=yes_to_all 76 )
CommuneX CLI 0.1.35
This command line interface is under development and subject to change.