Skip to content

Commit c11773e

Browse files
authored
Merge pull request #591 from opentensor/fix/thewhaleking/no-prompts
Unstake no prompts
2 parents ab51411 + e96a5c8 commit c11773e

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

bittensor_cli/cli.py

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import warnings
1313
from dataclasses import fields
1414
from pathlib import Path
15-
from typing import Coroutine, Optional, Union
15+
from typing import Coroutine, Optional, Union, Literal
1616

1717
import numpy as np
1818
import rich
@@ -1671,7 +1671,7 @@ def wallet_ask(
16711671
wallet_name: Optional[str],
16721672
wallet_path: Optional[str],
16731673
wallet_hotkey: Optional[str],
1674-
ask_for: Optional[list[str]] = None,
1674+
ask_for: Optional[list[Literal[WO.NAME, WO.PATH, WO.HOTKEY]]] = None,
16751675
validate: WV = WV.WALLET,
16761676
return_wallet_and_hotkey: bool = False,
16771677
) -> Union[Wallet, tuple[Wallet, str]]:
@@ -3798,11 +3798,11 @@ def stake_remove(
37983798
"Interactive mode cannot be used with hotkey selection options like "
37993799
"--include-hotkeys, --exclude-hotkeys, --all-hotkeys, or --hotkey."
38003800
)
3801-
raise typer.Exit()
3801+
return False
38023802

38033803
if unstake_all and unstake_all_alpha:
38043804
print_error("Cannot specify both unstake-all and unstake-all-alpha.")
3805-
raise typer.Exit()
3805+
return False
38063806

38073807
if not interactive and not unstake_all and not unstake_all_alpha:
38083808
netuid = get_optional_netuid(netuid, all_netuids)
@@ -3811,23 +3811,39 @@ def stake_remove(
38113811
"You have specified hotkeys to include and also the `--all-hotkeys` flag. The flag"
38123812
" should only be used standalone (to use all hotkeys) or with `--exclude-hotkeys`."
38133813
)
3814-
raise typer.Exit()
3814+
return False
38153815

38163816
if include_hotkeys and exclude_hotkeys:
38173817
print_error(
38183818
"You have specified both including and excluding hotkeys options. Select one or the other."
38193819
)
3820-
raise typer.Exit()
3820+
return False
38213821

38223822
if unstake_all and amount:
38233823
print_error(
38243824
"Cannot specify both a specific amount and 'unstake-all'. Choose one or the other."
38253825
)
3826-
raise typer.Exit()
3826+
return False
38273827

38283828
if amount and amount <= 0:
38293829
print_error(f"You entered an incorrect unstake amount: {amount}")
3830-
raise typer.Exit()
3830+
return False
3831+
3832+
if include_hotkeys:
3833+
include_hotkeys = parse_to_list(
3834+
include_hotkeys,
3835+
str,
3836+
"Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`.",
3837+
is_ss58=False,
3838+
)
3839+
3840+
if exclude_hotkeys:
3841+
exclude_hotkeys = parse_to_list(
3842+
exclude_hotkeys,
3843+
str,
3844+
"Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`.",
3845+
is_ss58=False,
3846+
)
38313847

38323848
if (
38333849
not wallet_hotkey
@@ -3844,7 +3860,8 @@ def stake_remove(
38443860
default=self.config.get("wallet_name") or defaults.wallet.name,
38453861
)
38463862
hotkey_or_ss58 = Prompt.ask(
3847-
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim](or Press Enter to view existing staked hotkeys)[/dim]",
3863+
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake from [dim]"
3864+
"(or Press Enter to view existing staked hotkeys)[/dim]",
38483865
)
38493866
if hotkey_or_ss58 == "":
38503867
wallet = self.wallet_ask(
@@ -3875,12 +3892,12 @@ def stake_remove(
38753892
if include_hotkeys:
38763893
if len(include_hotkeys) > 1:
38773894
print_error("Cannot unstake_all from multiple hotkeys at once.")
3878-
raise typer.Exit()
3895+
return False
38793896
elif is_valid_ss58_address(include_hotkeys[0]):
38803897
hotkey_ss58_address = include_hotkeys[0]
38813898
else:
38823899
print_error("Invalid hotkey ss58 address.")
3883-
raise typer.Exit()
3900+
return False
38843901
elif all_hotkeys:
38853902
wallet = self.wallet_ask(
38863903
wallet_name,
@@ -3891,7 +3908,8 @@ def stake_remove(
38913908
else:
38923909
if not hotkey_ss58_address and not wallet_hotkey:
38933910
hotkey_or_ss58 = Prompt.ask(
3894-
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim](or enter 'all' to unstake from all hotkeys)[/dim]",
3911+
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim]"
3912+
"(or enter 'all' to unstake from all hotkeys)[/dim]",
38953913
default=self.config.get("wallet_hotkey")
38963914
or defaults.wallet.hotkey,
38973915
)
@@ -3957,22 +3975,23 @@ def stake_remove(
39573975
ask_for=[WO.NAME, WO.PATH, WO.HOTKEY],
39583976
validate=WV.WALLET_AND_HOTKEY,
39593977
)
3960-
3961-
if include_hotkeys:
3962-
include_hotkeys = parse_to_list(
3963-
include_hotkeys,
3964-
str,
3965-
"Hotkeys must be a comma-separated list of ss58s or names, e.g., `--include-hotkeys hk1,hk2`.",
3966-
is_ss58=False,
3978+
if not amount and not prompt:
3979+
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}]"
39673983
)
3984+
return False
39683985

3969-
if exclude_hotkeys:
3970-
exclude_hotkeys = parse_to_list(
3971-
exclude_hotkeys,
3972-
str,
3973-
"Hotkeys must be a comma-separated list of ss58s or names, e.g., `--exclude-hotkeys hk3,hk4`.",
3974-
is_ss58=False,
3986+
if not amount and json_output:
3987+
json_console.print_json(
3988+
data={
3989+
"success": False,
3990+
"err_msg": "Ambiguous request! Specify '--amount', '--all', "
3991+
"or '--all-alpha' to use '--json-output'",
3992+
}
39753993
)
3994+
return False
39763995

39773996
return self._run_command(
39783997
remove_stake.unstake(

0 commit comments

Comments
 (0)