opentensor / btcli

Bittensor command line tool
https://docs.bittensor.com/btcli
9 stars 2 forks source link

Don't allow multiple options #160

Open thewhaleking opened 6 hours ago

thewhaleking commented 6 hours ago

Typer allows multiple uses of the same option, and then just uses whichever was specified last. E.g. in btcli w balance --network ws://127.0.0.1:9945 --network local, it would use local and completely ignore the specified chain endpoint. This is usually not a big deal, but we have a number of aliases for network specifically:

"--network"
"--subtensor.network"
"--chain"
"--subtensor.chain_endpoint"

This can cause some confusion amongst people who are used to specifying --subtensor.network and --subtensor.chain_endpoint.

~We can validate a single use of the commands with a callback, like so:~ This does not work:

def validate_single_use(value: str, previous: str = None):
    if previous is not None:
        raise typer.BadParameter(f"Option '--network' was already used: {previous}")
    return value

@app.command()
def balance(
    network: str = typer.Option(None, "--network", callback=validate_single_use)
):
    typer.echo(f"Using network: {network}")
thewhaleking commented 4 hours ago

Options, as I can see:

  1. Write a new parser for Typer (super parser, not option-level)
  2. Remove --chain and --subtensor.chain_endpoint aliases for network.