-
For example, with following code, I can do #[derive(Subcommand)]
#[command(rename_all = "lower")]
enum SubCmd {
PgSql {
#[arg(short, long)]
username: String,
},
}
#[derive(Parser)]
struct Cli {
#[arg(short('s'), long)]
secret_name: String,
#[arg(short('n'), long, default_value = "default")]
secret_namespace: String,
#[arg(short('l'), long, default_value = "16")]
secret_length: u8,
#[command(subcommand)]
cmd: SubCmd,
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can mark arguments with Generally, the expectation is that a subcommand is self-contained. Also, this can lead to confusing situations where a global flag exists but doesn't apply to all commands. This can be a form of false-sharing, much like false-sharing in code when doing DRY or memory when using cache lines. Since you mentioned "being more flexible", one route would allow arguments under |
Beta Was this translation helpful? Give feedback.
You can mark arguments with
global = true
onCli
so they are available withinPgSql
however I would recommend against it.Generally, the expectation is that a subcommand is self-contained.
Also, this can lead to confusing situations where a global flag exists but doesn't apply to all commands. This can be a form of false-sharing, much like false-sharing in code when doing DRY or memory when using cache lines.
Since you mentioned "being more flexible", one route would allow arguments under
pgsql
to show up before the command. Again, that generally breaks expectations, especially in understanding commands because they are expected to be read left-to-right. On top of that, this left-to-right…