From 42331cb172ed246b5c9207472598e328a3bd95b8 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 20:24:24 +0200 Subject: [PATCH 1/6] Allow custom config path using env var --- bittensor_cli/cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index b4b4afbea..90e405b57 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -655,7 +655,9 @@ def __init__(self): self.event_loop = asyncio.new_event_loop() self.config_base_path = os.path.expanduser(defaults.config.base_path) - self.config_path = os.path.expanduser(defaults.config.path) + self.config_path = os.getenv("BTCLI_CONFIG_PATH") or os.path.expanduser( + defaults.config.path + ) self.app = typer.Typer( rich_markup_mode="rich", @@ -663,7 +665,12 @@ def __init__(self): epilog=_epilog, no_args_is_help=True, ) - self.config_app = typer.Typer(epilog=_epilog) + self.config_app = typer.Typer( + epilog=_epilog, + help=f"Allows for getting/setting the config. " + f"Default path for the config file is [{COLORS.G.ARG}]{defaults.config.path}[/{COLORS.G.ARG}]. " + f"You can set your own with the env var [{COLORS.G.ARG}]BTCLI_CONFIG_PATH[/{COLORS.G.ARG}]", + ) self.wallet_app = typer.Typer(epilog=_epilog) self.stake_app = typer.Typer(epilog=_epilog) self.sudo_app = typer.Typer(epilog=_epilog) @@ -1497,6 +1504,8 @@ def get_config(self): Column("[bold white]Value", style="gold1"), Column("", style="medium_purple"), box=box.SIMPLE_HEAD, + title=f"[{COLORS.G.HEADER}]BTCLI Config[/{COLORS.G.HEADER}]: " + f"[{COLORS.G.ARG}]{self.config_path}[/{COLORS.G.ARG}]", ) for key, value in self.config.items(): From 24387012b3cd2ad3dded964a1aa981dba2e9841b Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 22:32:36 +0200 Subject: [PATCH 2/6] Respect config sets --- bittensor_cli/cli.py | 49 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 90e405b57..7768f02e9 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2233,14 +2233,15 @@ def wallet_regen_coldkey( if not wallet_path: wallet_path = Prompt.ask( - "Enter the path for the wallets directory", default=defaults.wallet.path + "Enter the path for the wallets directory", + default=self.config.get("wallet_path") or defaults.wallet.path, ) wallet_path = os.path.expanduser(wallet_path) if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=defaults.wallet.name, + default=self.config.get("wallet_name") or defaults.wallet.name, ) wallet = Wallet(wallet_name, wallet_hotkey, wallet_path) @@ -2292,14 +2293,15 @@ def wallet_regen_coldkey_pub( if not wallet_path: wallet_path = Prompt.ask( - "Enter the path to the wallets directory", default=defaults.wallet.path + "Enter the path to the wallets directory", + default=self.config.get("wallet_path") or defaults.wallet.path, ) wallet_path = os.path.expanduser(wallet_path) if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=defaults.wallet.name, + default=self.config.get("wallet_name") or defaults.wallet.name, ) wallet = Wallet(wallet_name, wallet_hotkey, wallet_path) @@ -2418,18 +2420,6 @@ def wallet_new_hotkey( """ self.verbosity_handler(quiet, verbose, json_output) - if not wallet_name: - wallet_name = Prompt.ask( - f"Enter the [{COLORS.G.CK}]wallet name", - default=defaults.wallet.name, - ) - - if not wallet_hotkey: - wallet_hotkey = Prompt.ask( - f"Enter the name of the [{COLORS.G.HK}]new hotkey", - default=defaults.wallet.hotkey, - ) - wallet = self.wallet_ask( wallet_name, wallet_path, @@ -2479,8 +2469,7 @@ def wallet_associate_hotkey( "[blue]hotkey ss58 address[/blue] [dim](to associate with your coldkey)[/dim]" ) - hotkey_display = None - if is_valid_ss58_address(wallet_hotkey): + if wallet_hotkey and is_valid_ss58_address(wallet_hotkey): hotkey_ss58 = wallet_hotkey wallet = self.wallet_ask( wallet_name, @@ -2501,7 +2490,10 @@ def wallet_associate_hotkey( validate=WV.WALLET_AND_HOTKEY, ) hotkey_ss58 = wallet.hotkey.ss58_address - hotkey_display = f"hotkey [blue]{wallet_hotkey}[/blue] [{COLORS.GENERAL.HK}]({hotkey_ss58})[/{COLORS.GENERAL.HK}]" + hotkey_display = ( + f"hotkey [blue]{wallet_hotkey}[/blue] " + f"[{COLORS.GENERAL.HK}]({hotkey_ss58})[/{COLORS.GENERAL.HK}]" + ) return self._run_command( wallets.associate_hotkey( @@ -2627,7 +2619,8 @@ def wallet_check_ck_swap( if not wallet_ss58_address: wallet_ss58_address = Prompt.ask( - "Enter [blue]wallet name[/blue] or [blue]SS58 address[/blue] [dim](leave blank to show all pending swaps)[/dim]" + "Enter [blue]wallet name[/blue] or [blue]SS58 address[/blue] [dim]" + "(leave blank to show all pending swaps)[/dim]" ) if not wallet_ss58_address: return self._run_command( @@ -2691,18 +2684,19 @@ def wallet_create_wallet( self.verbosity_handler(quiet, verbose, json_output) if not wallet_path: wallet_path = Prompt.ask( - "Enter the path of wallets directory", default=defaults.wallet.path + "Enter the path of wallets directory", + default=self.config.get("wallet_path") or defaults.wallet.path, ) if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=defaults.wallet.name, + default=self.config.get("wallet_name") or defaults.wallet.name, ) if not wallet_hotkey: wallet_hotkey = Prompt.ask( f"Enter the the name of the [{COLORS.G.HK}]new hotkey", - default=defaults.wallet.hotkey, + default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, ) wallet = self.wallet_ask( @@ -3999,7 +3993,8 @@ def stake_move( origin_hotkey = Prompt.ask( "Enter the [blue]origin hotkey[/blue] name or " "[blue]ss58 address[/blue] where the stake will be moved from " - "[dim](or Press Enter to view existing stakes)[/dim]" + "[dim](or Press Enter to view existing stakes)[/dim]", + default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, ) if origin_hotkey == "": interactive_selection = True @@ -4162,8 +4157,10 @@ def stake_transfer( interactive_selection = False if not wallet_hotkey: origin_hotkey = Prompt.ask( - "Enter the [blue]origin hotkey[/blue] name or ss58 address [bold](stake will be transferred FROM here)[/bold] " - "[dim](or press Enter to select from existing stakes)[/dim]" + "Enter the [blue]origin hotkey[/blue] name or ss58 address [bold]" + "(stake will be transferred FROM here)[/bold] " + "[dim](or press Enter to select from existing stakes)[/dim]", + default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, ) if origin_hotkey == "": interactive_selection = True From b121e6785dda5b0d44dc9440b18ba61f912a1072 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 22:35:26 +0200 Subject: [PATCH 3/6] Add more defaults. --- bittensor_cli/cli.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 7768f02e9..f1ac15320 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2466,7 +2466,8 @@ def wallet_associate_hotkey( if not wallet_hotkey: wallet_hotkey = Prompt.ask( "Enter the [blue]hotkey[/blue] name or " - "[blue]hotkey ss58 address[/blue] [dim](to associate with your coldkey)[/dim]" + "[blue]hotkey ss58 address[/blue] [dim](to associate with your coldkey)[/dim]", + default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, ) if wallet_hotkey and is_valid_ss58_address(wallet_hotkey): @@ -2540,13 +2541,14 @@ def wallet_new_coldkey( if not wallet_path: wallet_path = Prompt.ask( - "Enter the path to the wallets directory", default=defaults.wallet.path + "Enter the path to the wallets directory", + default=self.config.get("wallet_path") or defaults.wallet.path, ) if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=defaults.wallet.name, + default=self.config.get("wallet_name") or defaults.wallet.name, ) wallet = self.wallet_ask( From ba7cca5d25e656b14ec10f8123a2bd755b0309e9 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 22:40:37 +0200 Subject: [PATCH 4/6] Removed some defaults --- bittensor_cli/cli.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index f1ac15320..bc95fd39b 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -3995,8 +3995,7 @@ def stake_move( origin_hotkey = Prompt.ask( "Enter the [blue]origin hotkey[/blue] name or " "[blue]ss58 address[/blue] where the stake will be moved from " - "[dim](or Press Enter to view existing stakes)[/dim]", - default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, + "[dim](or Press Enter to view existing stakes)[/dim]" ) if origin_hotkey == "": interactive_selection = True @@ -4161,8 +4160,7 @@ def stake_transfer( origin_hotkey = Prompt.ask( "Enter the [blue]origin hotkey[/blue] name or ss58 address [bold]" "(stake will be transferred FROM here)[/bold] " - "[dim](or press Enter to select from existing stakes)[/dim]", - default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, + "[dim](or press Enter to select from existing stakes)[/dim]" ) if origin_hotkey == "": interactive_selection = True From e4ba58683bbf682bd9ea7fb9a49dda03251b63cc Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 22:42:28 +0200 Subject: [PATCH 5/6] More defaults --- bittensor_cli/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index bc95fd39b..587fec973 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2420,6 +2420,18 @@ def wallet_new_hotkey( """ self.verbosity_handler(quiet, verbose, json_output) + if not wallet_name: + wallet_name = Prompt.ask( + f"Enter the [{COLORS.G.CK}]wallet name", + default=self.config.get("wallet_name") or defaults.wallet.name, + ) + + if not wallet_hotkey: + wallet_hotkey = Prompt.ask( + f"Enter the name of the [{COLORS.G.HK}]new hotkey", + default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, + ) + wallet = self.wallet_ask( wallet_name, wallet_path, From 452411911dd21d778a0c8540c17d167b9594fff0 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 5 Aug 2025 22:58:47 +0200 Subject: [PATCH 6/6] Removed some defaults --- bittensor_cli/cli.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 587fec973..961a1f0f2 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2301,7 +2301,7 @@ def wallet_regen_coldkey_pub( if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=self.config.get("wallet_name") or defaults.wallet.name, + default=defaults.wallet.name, ) wallet = Wallet(wallet_name, wallet_hotkey, wallet_path) @@ -2429,7 +2429,7 @@ def wallet_new_hotkey( if not wallet_hotkey: wallet_hotkey = Prompt.ask( f"Enter the name of the [{COLORS.G.HK}]new hotkey", - default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey, + default=defaults.wallet.hotkey, ) wallet = self.wallet_ask( @@ -2705,7 +2705,6 @@ def wallet_create_wallet( if not wallet_name: wallet_name = Prompt.ask( f"Enter the name of the [{COLORS.G.CK}]new wallet (coldkey)", - default=self.config.get("wallet_name") or defaults.wallet.name, ) if not wallet_hotkey: wallet_hotkey = Prompt.ask(