-
I have a simple struct with a subcommand and 1 argument: #[derive(Debug, clap::Parser)]
#[command(version)]
struct Cli {
#[clap(subcommand)]
action: Action,
/// Server location
#[arg(short, long, default_value = "127.0.0.1:4000")]
addr: String,
} If I enter |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Once we start parsing a subcommand, we cannot parse arguments from a parent command. There is a caveat to this that I'll get to. Is |
Beta Was this translation helpful? Give feedback.
Once we start parsing a subcommand, we cannot parse arguments from a parent command. There is a caveat to this that I'll get to.
Is
addr
truly universal between your subcommands or is this purely for coding convenience? From a CLI design perspective, I generally recommend that the focus be on arguments to your subcommands. The reason to have arguments on your parent command are if they are mutually exclusive with commands (e.g.cargo --list
) or if they are orthogonal to subcommands (e.g.cargo --verbose
) but even those can be suspect as it is generally expected to runcargo check -v
rather thancargo -v check
. It is also easy to think that an argument is universal to all commands until a …