Skip to content

Commit 8be86e7

Browse files
committed
Merge branch 'staging' into feat/thewhaleking/debug-cmd
# Conflicts: # bittensor_cli/cli.py
2 parents 5ab9e8b + 2e6a7ef commit 8be86e7

File tree

1 file changed

+30
-43
lines changed

1 file changed

+30
-43
lines changed

bittensor_cli/cli.py

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class GitError(Exception):
9393
np.set_printoptions(precision=8, suppress=True, floatmode="fixed")
9494

9595

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+
96103
class Options:
97104
"""
98105
Re-usable typer args
@@ -702,8 +709,8 @@ def __init__(self):
702709
self.config_app = typer.Typer(
703710
epilog=_epilog,
704711
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')}",
707714
)
708715
self.wallet_app = typer.Typer(epilog=_epilog)
709716
self.stake_app = typer.Typer(epilog=_epilog)
@@ -1134,7 +1141,7 @@ def initialize_chain(
11341141
if not_selected_networks:
11351142
console.print(
11361143
f"Networks not selected: "
1137-
f"[{COLORS.G.ARG}]{', '.join(not_selected_networks)}[/{COLORS.G.ARG}]"
1144+
f"{arg__(', '.join(not_selected_networks))}"
11381145
)
11391146

11401147
self.subtensor = SubtensorInterface(
@@ -1445,8 +1452,7 @@ def set_config(
14451452
if n := args.get("network"):
14461453
if n in Constants.networks:
14471454
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"
14501456
"Do you want to continue?"
14511457
):
14521458
typer.Exit()
@@ -1461,14 +1467,13 @@ def set_config(
14611467
)
14621468
args["network"] = known_network
14631469
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"
14661471
"Do you want to continue?"
14671472
):
14681473
raise typer.Exit()
14691474
else:
14701475
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"
14721477
"Do you want to continue?"
14731478
):
14741479
raise typer.Exit()
@@ -1543,41 +1548,32 @@ def del_config(
15431548
if not any(args.values()):
15441549
for arg in args.keys():
15451550
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?"):
15491552
logger.debug(f"Config: clearing {arg}.")
15501553
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'.")
15541555
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.")
15581557

15591558
else:
15601559
# Check each specified argument
15611560
for arg, should_clear in args.items():
15621561
if should_clear:
15631562
if self.config.get(arg) is not None:
15641563
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)}"
15661565
f" [bold cyan]({self.config.get(arg)})[/bold cyan] config?"
15671566
):
15681567
self.config[arg] = None
15691568
logger.debug(f"Config: clearing {arg}.")
15701569
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'."
15721571
)
15731572
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.")
15771574
else:
15781575
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."
15811577
)
15821578
with open(self.config_path, "w") as f:
15831579
safe_dump(self.config, f)
@@ -1593,8 +1589,7 @@ def get_config(self):
15931589
Column("[bold white]Value", style="gold1"),
15941590
Column("", style="medium_purple"),
15951591
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)}",
15981593
)
15991594

16001595
for key, value in self.config.items():
@@ -4146,9 +4141,8 @@ def stake_remove(
41464141
)
41474142
if not amount and not prompt:
41484143
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')}"
41524146
)
41534147
return False
41544148

@@ -5050,12 +5044,8 @@ def sudo_set(
50505044
)
50515045
return False
50525046
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')}")
50595049
param_value = f"{low_val},{high_val}"
50605050
if param_name == "yuma_version":
50615051
if not prompt:
@@ -5079,7 +5069,7 @@ def sudo_set(
50795069
if param_name == "subnet_is_active":
50805070
err_console.print(
50815071
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."
50835073
)
50845074
return False
50855075

@@ -5429,14 +5419,12 @@ def subnets_price(
54295419
"""
54305420
if json_output and html_output:
54315421
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')}"
54345423
)
54355424
return
54365425
if current_only and html_output:
54375426
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')}"
54405428
)
54415429
return
54425430
self.verbosity_handler(quiet=quiet, verbose=verbose, json_output=json_output)
@@ -5447,9 +5435,8 @@ def subnets_price(
54475435
Constants.network_map[x] for x in non_archives
54485436
]:
54495437
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."
54535440
)
54545441
return False
54555442

0 commit comments

Comments
 (0)