@@ -91,6 +91,13 @@ class GitError(Exception):
91
91
np .set_printoptions (precision = 8 , suppress = True , floatmode = "fixed" )
92
92
93
93
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
+
94
101
class Options :
95
102
"""
96
103
Re-usable typer args
@@ -675,8 +682,8 @@ def __init__(self):
675
682
self .config_app = typer .Typer (
676
683
epilog = _epilog ,
677
684
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' ) } " ,
680
687
)
681
688
self .wallet_app = typer .Typer (epilog = _epilog )
682
689
self .stake_app = typer .Typer (epilog = _epilog )
@@ -1107,7 +1114,7 @@ def initialize_chain(
1107
1114
if not_selected_networks :
1108
1115
console .print (
1109
1116
f"Networks not selected: "
1110
- f"[ { COLORS . G . ARG } ] { ', ' .join (not_selected_networks )} [/ { COLORS . G . ARG } ] "
1117
+ f"{ arg__ ( ', ' .join (not_selected_networks )) } "
1111
1118
)
1112
1119
1113
1120
self .subtensor = SubtensorInterface (
@@ -1389,8 +1396,7 @@ def set_config(
1389
1396
if n := args .get ("network" ):
1390
1397
if n in Constants .networks :
1391
1398
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 "
1394
1400
"Do you want to continue?"
1395
1401
):
1396
1402
typer .Exit ()
@@ -1405,14 +1411,13 @@ def set_config(
1405
1411
)
1406
1412
args ["network" ] = known_network
1407
1413
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 "
1410
1415
"Do you want to continue?"
1411
1416
):
1412
1417
raise typer .Exit ()
1413
1418
else :
1414
1419
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 "
1416
1421
"Do you want to continue?"
1417
1422
):
1418
1423
raise typer .Exit ()
@@ -1486,39 +1491,30 @@ def del_config(
1486
1491
if not any (args .values ()):
1487
1492
for arg in args .keys ():
1488
1493
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?" ):
1492
1495
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'." )
1496
1497
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." )
1500
1499
1501
1500
else :
1502
1501
# Check each specified argument
1503
1502
for arg , should_clear in args .items ():
1504
1503
if should_clear :
1505
1504
if self .config .get (arg ) is not None :
1506
1505
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 ) } "
1508
1507
f" [bold cyan]({ self .config .get (arg )} )[/bold cyan] config?"
1509
1508
):
1510
1509
self .config [arg ] = None
1511
1510
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'."
1513
1512
)
1514
1513
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." )
1518
1515
else :
1519
1516
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."
1522
1518
)
1523
1519
with open (self .config_path , "w" ) as f :
1524
1520
safe_dump (self .config , f )
@@ -1534,8 +1530,7 @@ def get_config(self):
1534
1530
Column ("[bold white]Value" , style = "gold1" ),
1535
1531
Column ("" , style = "medium_purple" ),
1536
1532
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 )} " ,
1539
1534
)
1540
1535
1541
1536
for key , value in self .config .items ():
@@ -3977,9 +3972,8 @@ def stake_remove(
3977
3972
)
3978
3973
if not amount and not prompt :
3979
3974
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' )} "
3983
3977
)
3984
3978
return False
3985
3979
@@ -4806,12 +4800,8 @@ def sudo_set(
4806
4800
)
4807
4801
return False
4808
4802
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' )} " )
4815
4805
param_value = f"{ low_val } ,{ high_val } "
4816
4806
if param_name == "yuma_version" :
4817
4807
if not prompt :
@@ -4835,7 +4825,7 @@ def sudo_set(
4835
4825
if param_name == "subnet_is_active" :
4836
4826
err_console .print (
4837
4827
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."
4839
4829
)
4840
4830
return False
4841
4831
@@ -5177,14 +5167,12 @@ def subnets_price(
5177
5167
"""
5178
5168
if json_output and html_output :
5179
5169
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' )} "
5182
5171
)
5183
5172
return
5184
5173
if current_only and html_output :
5185
5174
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' )} "
5188
5176
)
5189
5177
return
5190
5178
self .verbosity_handler (quiet = quiet , verbose = verbose , json_output = json_output )
@@ -5195,9 +5183,8 @@ def subnets_price(
5195
5183
Constants .network_map [x ] for x in non_archives
5196
5184
]:
5197
5185
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."
5201
5188
)
5202
5189
return False
5203
5190
0 commit comments