@@ -93,6 +93,13 @@ class GitError(Exception):
93
93
np .set_printoptions (precision = 8 , suppress = True , floatmode = "fixed" )
94
94
95
95
96
+ def arg__ (arg_name : str ) -> str :
97
+ """
98
+ Helper function to 'arg' format a string for rich console
99
+ """
100
+ return f"[{ COLORS .G .ARG } ]{ arg_name } [/{ COLORS .G .ARG } ]"
101
+
102
+
96
103
class Options :
97
104
"""
98
105
Re-usable typer args
@@ -702,8 +709,8 @@ def __init__(self):
702
709
self .config_app = typer .Typer (
703
710
epilog = _epilog ,
704
711
help = f"Allows for getting/setting the config. "
705
- f"Default path for the config file is [ { COLORS . G . ARG } ] { defaults .config .path } [/ { COLORS . G . ARG } ] . "
706
- f"You can set your own with the env var [ { COLORS . G . ARG } ] BTCLI_CONFIG_PATH[/ { COLORS . G . ARG } ] " ,
712
+ f"Default path for the config file is { arg__ ( defaults .config .path ) } . "
713
+ f"You can set your own with the env var { arg__ ( ' BTCLI_CONFIG_PATH' ) } " ,
707
714
)
708
715
self .wallet_app = typer .Typer (epilog = _epilog )
709
716
self .stake_app = typer .Typer (epilog = _epilog )
@@ -1134,7 +1141,7 @@ def initialize_chain(
1134
1141
if not_selected_networks :
1135
1142
console .print (
1136
1143
f"Networks not selected: "
1137
- f"[ { COLORS . G . ARG } ] { ', ' .join (not_selected_networks )} [/ { COLORS . G . ARG } ] "
1144
+ f"{ arg__ ( ', ' .join (not_selected_networks )) } "
1138
1145
)
1139
1146
1140
1147
self .subtensor = SubtensorInterface (
@@ -1445,8 +1452,7 @@ def set_config(
1445
1452
if n := args .get ("network" ):
1446
1453
if n in Constants .networks :
1447
1454
if not Confirm .ask (
1448
- f"You provided a network [{ COLORS .G .ARG } ]{ n } [/{ COLORS .G .ARG } ] which is mapped to "
1449
- f"[{ COLORS .G .ARG } ]{ Constants .network_map [n ]} [/{ COLORS .G .ARG } ]\n "
1455
+ f"You provided a network { arg__ (n )} which is mapped to { arg__ (Constants .network_map [n ])} \n "
1450
1456
"Do you want to continue?"
1451
1457
):
1452
1458
typer .Exit ()
@@ -1461,14 +1467,13 @@ def set_config(
1461
1467
)
1462
1468
args ["network" ] = known_network
1463
1469
if not Confirm .ask (
1464
- f"You provided an endpoint [{ COLORS .G .ARG } ]{ n } [/{ COLORS .G .ARG } ] which is mapped to "
1465
- f"[{ COLORS .G .ARG } ]{ known_network } [/{ COLORS .G .ARG } ]\n "
1470
+ f"You provided an endpoint { arg__ (n )} which is mapped to { arg__ (known_network )} \n "
1466
1471
"Do you want to continue?"
1467
1472
):
1468
1473
raise typer .Exit ()
1469
1474
else :
1470
1475
if not Confirm .ask (
1471
- f"You provided a chain endpoint URL [ { COLORS . G . ARG } ] { n } [/ { COLORS . G . ARG } ] \n "
1476
+ f"You provided a chain endpoint URL { arg__ ( n ) } \n "
1472
1477
"Do you want to continue?"
1473
1478
):
1474
1479
raise typer .Exit ()
@@ -1543,41 +1548,32 @@ def del_config(
1543
1548
if not any (args .values ()):
1544
1549
for arg in args .keys ():
1545
1550
if self .config .get (arg ) is not None :
1546
- if Confirm .ask (
1547
- f"Do you want to clear the [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config?"
1548
- ):
1551
+ if Confirm .ask (f"Do you want to clear the { arg__ (arg )} config?" ):
1549
1552
logger .debug (f"Config: clearing { arg } ." )
1550
1553
self .config [arg ] = None
1551
- console .print (
1552
- f"Cleared [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config and set to 'None'."
1553
- )
1554
+ console .print (f"Cleared { arg__ (arg )} config and set to 'None'." )
1554
1555
else :
1555
- console .print (
1556
- f"Skipped clearing [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config."
1557
- )
1556
+ console .print (f"Skipped clearing { arg__ (arg )} config." )
1558
1557
1559
1558
else :
1560
1559
# Check each specified argument
1561
1560
for arg , should_clear in args .items ():
1562
1561
if should_clear :
1563
1562
if self .config .get (arg ) is not None :
1564
1563
if Confirm .ask (
1565
- f"Do you want to clear the [ { COLORS . G . ARG } ] { arg } [/ { COLORS . G . ARG } ] "
1564
+ f"Do you want to clear the { arg__ ( arg ) } "
1566
1565
f" [bold cyan]({ self .config .get (arg )} )[/bold cyan] config?"
1567
1566
):
1568
1567
self .config [arg ] = None
1569
1568
logger .debug (f"Config: clearing { arg } ." )
1570
1569
console .print (
1571
- f"Cleared [ { COLORS . G . ARG } ] { arg } [/ { COLORS . G . ARG } ] config and set to 'None'."
1570
+ f"Cleared { arg__ ( arg ) } config and set to 'None'."
1572
1571
)
1573
1572
else :
1574
- console .print (
1575
- f"Skipped clearing [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ] config."
1576
- )
1573
+ console .print (f"Skipped clearing { arg__ (arg )} config." )
1577
1574
else :
1578
1575
console .print (
1579
- f"No config set for [{ COLORS .G .ARG } ]{ arg } [/{ COLORS .G .ARG } ]."
1580
- f" Use [{ COLORS .G .ARG } ]`btcli config set`[/{ COLORS .G .ARG } ] to set it."
1576
+ f"No config set for { arg__ (arg )} . Use { arg__ ('btcli config set' )} to set it."
1581
1577
)
1582
1578
with open (self .config_path , "w" ) as f :
1583
1579
safe_dump (self .config , f )
@@ -1593,8 +1589,7 @@ def get_config(self):
1593
1589
Column ("[bold white]Value" , style = "gold1" ),
1594
1590
Column ("" , style = "medium_purple" ),
1595
1591
box = box .SIMPLE_HEAD ,
1596
- title = f"[{ COLORS .G .HEADER } ]BTCLI Config[/{ COLORS .G .HEADER } ]: "
1597
- f"[{ COLORS .G .ARG } ]{ self .config_path } [/{ COLORS .G .ARG } ]" ,
1592
+ title = f"[{ COLORS .G .HEADER } ]BTCLI Config[/{ COLORS .G .HEADER } ]: { arg__ (self .config_path )} " ,
1598
1593
)
1599
1594
1600
1595
for key , value in self .config .items ():
@@ -4146,9 +4141,8 @@ def stake_remove(
4146
4141
)
4147
4142
if not amount and not prompt :
4148
4143
print_error (
4149
- f"Ambiguous request! Specify [{ COLORS .G .ARG } ]--amount[/{ COLORS .G .ARG } ], "
4150
- f"[{ COLORS .G .ARG } ]--all[/{ COLORS .G .ARG } ], "
4151
- f"or [{ COLORS .G .ARG } ]--all-alpha[/{ COLORS .G .ARG } ] to use [{ COLORS .G .ARG } ]--no-prompt[/{ COLORS .G .ARG } ]"
4144
+ f"Ambiguous request! Specify { arg__ ('--amount' )} , { arg__ ('--all' )} , or { arg__ ('--all-alpha' )} "
4145
+ f"to use { arg__ ('--no-prompt' )} "
4152
4146
)
4153
4147
return False
4154
4148
@@ -5050,12 +5044,8 @@ def sudo_set(
5050
5044
)
5051
5045
return False
5052
5046
param_name = "alpha_values"
5053
- low_val = FloatPrompt .ask (
5054
- f"Enter the new value for [{ COLORS .G .ARG } ]alpha_low[/{ COLORS .G .ARG } ]"
5055
- )
5056
- high_val = FloatPrompt .ask (
5057
- f"Enter the new value for [{ COLORS .G .ARG } ]alpha_high[/{ COLORS .G .ARG } ]"
5058
- )
5047
+ low_val = FloatPrompt .ask (f"Enter the new value for { arg__ ('alpha_low' )} " )
5048
+ high_val = FloatPrompt .ask (f"Enter the new value for { arg__ ('alpha_high' )} " )
5059
5049
param_value = f"{ low_val } ,{ high_val } "
5060
5050
if param_name == "yuma_version" :
5061
5051
if not prompt :
@@ -5079,7 +5069,7 @@ def sudo_set(
5079
5069
if param_name == "subnet_is_active" :
5080
5070
err_console .print (
5081
5071
f"[{ COLORS .SU .HYPERPARAM } ]subnet_is_active[/{ COLORS .SU .HYPERPARAM } ] "
5082
- f"is set by using [ { COLORS . G . ARG } ]` btcli subnets start`[/ { COLORS . G . ARG } ] command."
5072
+ f"is set by using { arg__ ( ' btcli subnets start' ) } command."
5083
5073
)
5084
5074
return False
5085
5075
@@ -5429,14 +5419,12 @@ def subnets_price(
5429
5419
"""
5430
5420
if json_output and html_output :
5431
5421
print_error (
5432
- f"Cannot specify both [{ COLORS .G .ARG } ]--json-output[/{ COLORS .G .ARG } ] "
5433
- f"and [{ COLORS .G .ARG } ]--html[/{ COLORS .G .ARG } ]"
5422
+ f"Cannot specify both { arg__ ('--json-output' )} and { arg__ ('--html' )} "
5434
5423
)
5435
5424
return
5436
5425
if current_only and html_output :
5437
5426
print_error (
5438
- f"Cannot specify both [{ COLORS .G .ARG } ]--current[/{ COLORS .G .ARG } ] "
5439
- f"and [{ COLORS .G .ARG } ]--html[/{ COLORS .G .ARG } ]"
5427
+ f"Cannot specify both { arg__ ('--current' )} and { arg__ ('--html' )} "
5440
5428
)
5441
5429
return
5442
5430
self .verbosity_handler (quiet = quiet , verbose = verbose , json_output = json_output )
@@ -5447,9 +5435,8 @@ def subnets_price(
5447
5435
Constants .network_map [x ] for x in non_archives
5448
5436
]:
5449
5437
err_console .print (
5450
- f"[red]Error[/red] Running this command without [{ COLORS .G .ARG } ]--current[/{ COLORS .G .ARG } ] requires "
5451
- "use of an archive node. "
5452
- f"Try running again with the [{ COLORS .G .ARG } ]--network archive[/{ COLORS .G .ARG } ] flag."
5438
+ f"[red]Error[/red] Running this command without { arg__ ('--current' )} requires use of an archive node. "
5439
+ f"Try running again with the { arg__ ('--network archive' )} flag."
5453
5440
)
5454
5441
return False
5455
5442
0 commit comments