-
|
Is this the right way of implementing a use clap::{CommandFactory, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Debug, Subcommand)]
enum Commands {
/// foo's a bar
FooBar,
/// detailed version information
Version,
}
fn main() {
let cli = Cli::parse();
match cli.command {
Some(Commands::Version) => {
eprintln!("{}", Cli::command().render_long_version());
}
Some(cmd) => {
println!("{:?}", cmd);
}
None => {
println!("lol");
}
}
}Would it make sense to implement this subcommand into Clap itself by default? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'd print to stdout, instead of stderr, like Depending on the structure of your program, you want to make sure that you don't accidentally fallback into other behavior.
I'm surprised I'm not seeing a previous discussion on this but maybe I haven't found it yet. It would be a breaking change and would have to wait until v5 (which also means it could just be put under |
Beta Was this translation helpful? Give feedback.
I'd print to stdout, instead of stderr, like
--help.Depending on the structure of your program, you want to make sure that you don't accidentally fallback into other behavior.
I'm surprised I'm not seeing a previous discussion on this but maybe I haven't found it yet.
It would be a breaking change and would have to wait until v5 (which also means it could just be put under
unstable-v5feature flag). We'd need to weigh out the expectations (how regularly are these expected to be there?), costs (increased API size, binary bloat…