structopt icon indicating copy to clipboard operation
structopt copied to clipboard

Subcommand hijacks parent's about

Open CodeSandwich opened this issue 4 years ago • 2 comments

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!

CodeSandwich avatar May 14 '20 09:05 CodeSandwich

Thanks for the clear report.

TeXitoi avatar May 15 '20 06:05 TeXitoi

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

pizzamig avatar Jul 20 '20 21:07 pizzamig