structopt
structopt copied to clipboard
Subcommand hijacks parent's about
I have a simple program:
use structopt::StructOpt;
/// The main thing
#[derive(StructOpt)]
struct Main {
#[structopt(subcommand)]
subcommand: Subcommand,
}
/// The subcommand
#[derive(StructOpt)]
enum Subcommand {
A{}
}
fn main() {
Main::from_args();
}
When I run it with cargo run -- --help
, I get the following output:
poligon 0.1.0
The subcommand
USAGE:
poligon <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
a
help Prints this message or the help of the given subcommand(s)
The app description should be The main thing
, not The subcommand
!
Thanks for the clear report.
This also prevents flattening of struct with their own rustdoc:
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "structopt-bug", about = "Show a bug in Structopt")]
struct Opt {
#[structopt(flatten)]
v: Verbose,
}
/// Re-usable Verbose flag
#[derive(Debug, StructOpt)]
struct Verbose {
/// Enable the verbosity messages
#[structopt(short)]
verbose: bool,
}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
The cargo run -- -h
shows:
structopt-bug 0.1.0
Re-usable Verbose flag
USAGE:
structopt-bug [FLAGS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
-v Enable the verbosity messages