@@ -91,6 +91,13 @@ class GitError(Exception):
9191np .set_printoptions (precision = 8 , suppress = True , floatmode = "fixed" )
9292
9393
94+ def arg__ (arg_name : str ) -> str :
95+ """
96+ Helper function to 'arg' format a string for rich console
97+ """
98+ return f"[{ COLORS .G .ARG } ]{ arg_name } [/{ COLORS .G .ARG } ]"
99+
100+
94101class Options :
95102 """
96103 Re-usable typer args
@@ -675,8 +682,8 @@ def __init__(self):
675682 self .config_app = typer .Typer (
676683 epilog = _epilog ,
677684 help = f"Allows for getting/setting the config. "
678- f"Default path for the config file is [ { COLORS . G . ARG } ] { defaults .config .path } [/ { COLORS . G . ARG } ] . "
679- f"You can set your own with the env var [ { COLORS . G . ARG } ] BTCLI_CONFIG_PATH[/ { COLORS . G . ARG } ] " ,
685+ f"Default path for the config file is { arg__ ( defaults .config .path ) } . "
686+ f"You can set your own with the env var { arg__ ( ' BTCLI_CONFIG_PATH' ) } " ,
680687 )
681688 self .wallet_app = typer .Typer (epilog = _epilog )
682689 self .stake_app = typer .Typer (epilog = _epilog )
@@ -1107,7 +1114,7 @@ def initialize_chain(
11071114 if not_selected_networks :
11081115 console .print (
11091116 f"Networks not selected: "
1110- f"[ { COLORS . G . ARG } ] { ', ' .join (not_selected_networks )} [/ { COLORS . G . ARG } ] "
1117+ f"{ arg__ ( ', ' .join (not_selected_networks )) } "
11111118 )
11121119
11131120 self .subtensor = SubtensorInterface (
@@ -1389,8 +1396,7 @@ def set_config(
13891396 if n := args .get ("network" ):
13901397 if n in Constants .networks :
13911398 if not Confirm .ask (
1392- f"You provided a network [{ COLORS .G .ARG } ]{ n } [/{ COLORS .G .ARG } ] which is mapped to "
1393- f"[{ COLORS .G .ARG } ]{ Constants .network_map [n ]} [/{ COLORS .G .ARG } ]\n "
1399+ f"You provided a network { arg__ (n )} which is mapped to { arg__ (Constants .network_map [n ])} \n "
13941400 "Do you want to continue?"
13951401 ):
13961402 typer .Exit ()
@@ -1405,14 +1411,13 @@ def set_config(
14051411 )
14061412 args ["network" ] = known_network
14071413 if not Confirm .ask (
1408- f"You provided an endpoint [{ COLORS .G .ARG } ]{ n } [/{ COLORS .G .ARG } ] which is mapped to "
1409- f"[{ COLORS .G .ARG } ]{ known_network } [/{ COLORS .G .ARG } ]\n "
1414+ f"You provided an endpoint { arg__ (n )} which is mapped to { arg__ (known_network )} \n "
14101415 "Do you want to continue?"
14111416 ):
14121417 raise typer .Exit ()
14131418 else :
14141419 if not Confirm .ask (
1415- f"You provided a chain endpoint URL [ { COLORS . G . ARG } ] { n } [/ { COLORS . G . ARG } ] \n "
1420+ f"You provided a chain endpoint URL { arg__ ( n ) } \n "
14161421 "Do you want to continue?"
14171422 ):
14181423 raise typer .Exit ()
@@ -1486,39 +1491,30 @@ def del_config(
14861491 if not any (args .values ()):
14871492 for arg in args .keys ():
14881493 if self .config .get (arg ) is not None :
1489- if Confirm .ask (
1490- f"Do you want to clear the [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config?"
1491- ):
1494+ if Confirm .ask (f"Do you want to clear the { arg__ (arg )} config?" ):
14921495 self .config [arg ] = None
1493- console .print (
1494- f"Cleared [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config and set to 'None'."
1495- )
1496+ console .print (f"Cleared { arg__ (arg )} config and set to 'None'." )
14961497 else :
1497- console .print (
1498- f"Skipped clearing [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config."
1499- )
1498+ console .print (f"Skipped clearing { arg__ (arg )} config." )
15001499
15011500 else :
15021501 # Check each specified argument
15031502 for arg , should_clear in args .items ():
15041503 if should_clear :
15051504 if self .config .get (arg ) is not None :
15061505 if Confirm .ask (
1507- f"Do you want to clear the [ { COLORS . G . ARG } ] { arg } [/ { COLORS . G . ARG } ] "
1506+ f"Do you want to clear the { arg__ ( arg ) } "
15081507 f" [bold cyan]({ self .config .get (arg )} )[/bold cyan] config?"
15091508 ):
15101509 self .config [arg ] = None
15111510 console .print (
1512- f"Cleared [ { COLORS . G . ARG } ] { arg } [/ { COLORS . G . ARG } ] config and set to 'None'."
1511+ f"Cleared { arg__ ( arg ) } config and set to 'None'."
15131512 )
15141513 else :
1515- console .print (
1516- f"Skipped clearing [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config."
1517- )
1514+ console .print (f"Skipped clearing { arg__ (arg )} config." )
15181515 else :
15191516 console .print (
1520- f"No config set for [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ]."
1521- f" Use [{ COLORS .G .ARG } ]`btcli config set`[/{ COLORS .G .ARG } ] to set it."
1517+ f"No config set for { arg__ (arg )} . Use { arg__ ('btcli config set' )} to set it."
15221518 )
15231519 with open (self .config_path , "w" ) as f :
15241520 safe_dump (self .config , f )
@@ -1534,8 +1530,7 @@ def get_config(self):
15341530 Column ("[bold white]Value" , style = "gold1" ),
15351531 Column ("" , style = "medium_purple" ),
15361532 box = box .SIMPLE_HEAD ,
1537- title = f"[{ COLORS .G .HEADER } ]BTCLI Config[/{ COLORS .G .HEADER } ]: "
1538- f"[{ COLORS .G .ARG } ]{ self .config_path } [/{ COLORS .G .ARG } ]" ,
1533+ title = f"[{ COLORS .G .HEADER } ]BTCLI Config[/{ COLORS .G .HEADER } ]: { arg__ (self .config_path )} " ,
15391534 )
15401535
15411536 for key , value in self .config .items ():
@@ -3977,9 +3972,8 @@ def stake_remove(
39773972 )
39783973 if not amount and not prompt :
39793974 print_error (
3980- f"Ambiguous request! Specify [{ COLORS .G .ARG } ]--amount[/{ COLORS .G .ARG } ], "
3981- f"[{ COLORS .G .ARG } ]--all[/{ COLORS .G .ARG } ], "
3982- f"or [{ COLORS .G .ARG } ]--all-alpha[/{ COLORS .G .ARG } ] to use [{ COLORS .G .ARG } ]--no-prompt[/{ COLORS .G .ARG } ]"
3975+ f"Ambiguous request! Specify { arg__ ('--amount' )} , { arg__ ('--all' )} , or { arg__ ('--all-alpha' )} "
3976+ f"to use { arg__ ('--no-prompt' )} "
39833977 )
39843978 return False
39853979
@@ -4806,12 +4800,8 @@ def sudo_set(
48064800 )
48074801 return False
48084802 param_name = "alpha_values"
4809- low_val = FloatPrompt .ask (
4810- f"Enter the new value for [{ COLORS .G .ARG } ]alpha_low[/{ COLORS .G .ARG } ]"
4811- )
4812- high_val = FloatPrompt .ask (
4813- f"Enter the new value for [{ COLORS .G .ARG } ]alpha_high[/{ COLORS .G .ARG } ]"
4814- )
4803+ low_val = FloatPrompt .ask (f"Enter the new value for { arg__ ('alpha_low' )} " )
4804+ high_val = FloatPrompt .ask (f"Enter the new value for { arg__ ('alpha_high' )} " )
48154805 param_value = f"{ low_val } ,{ high_val } "
48164806 if param_name == "yuma_version" :
48174807 if not prompt :
@@ -4835,7 +4825,7 @@ def sudo_set(
48354825 if param_name == "subnet_is_active" :
48364826 err_console .print (
48374827 f"[{ COLORS .SU .HYPERPARAM } ]subnet_is_active[/{ COLORS .SU .HYPERPARAM } ] "
4838- f"is set by using [ { COLORS . G . ARG } ]` btcli subnets start`[/ { COLORS . G . ARG } ] command."
4828+ f"is set by using { arg__ ( ' btcli subnets start' ) } command."
48394829 )
48404830 return False
48414831
@@ -5177,14 +5167,12 @@ def subnets_price(
51775167 """
51785168 if json_output and html_output :
51795169 print_error (
5180- f"Cannot specify both [{ COLORS .G .ARG } ]--json-output[/{ COLORS .G .ARG } ] "
5181- f"and [{ COLORS .G .ARG } ]--html[/{ COLORS .G .ARG } ]"
5170+ f"Cannot specify both { arg__ ('--json-output' )} and { arg__ ('--html' )} "
51825171 )
51835172 return
51845173 if current_only and html_output :
51855174 print_error (
5186- f"Cannot specify both [{ COLORS .G .ARG } ]--current[/{ COLORS .G .ARG } ] "
5187- f"and [{ COLORS .G .ARG } ]--html[/{ COLORS .G .ARG } ]"
5175+ f"Cannot specify both { arg__ ('--current' )} and { arg__ ('--html' )} "
51885176 )
51895177 return
51905178 self .verbosity_handler (quiet = quiet , verbose = verbose , json_output = json_output )
@@ -5195,9 +5183,8 @@ def subnets_price(
51955183 Constants .network_map [x ] for x in non_archives
51965184 ]:
51975185 err_console .print (
5198- f"[red]Error[/red] Running this command without [{ COLORS .G .ARG } ]--current[/{ COLORS .G .ARG } ] requires "
5199- "use of an archive node. "
5200- f"Try running again with the [{ COLORS .G .ARG } ]--network archive[/{ COLORS .G .ARG } ] flag."
5186+ f"[red]Error[/red] Running this command without { arg__ ('--current' )} requires use of an archive node. "
5187+ f"Try running again with the { arg__ ('--network archive' )} flag."
52015188 )
52025189 return False
52035190
0 commit comments