Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcommand hijacks parent's about #391

Open
CodeSandwich opened this issue May 14, 2020 · 2 comments
Open

Subcommand hijacks parent's about #391

CodeSandwich opened this issue May 14, 2020 · 2 comments
Labels
bug This is a BUG. The fix may be released in a patch version even if considered breaking

Comments

@CodeSandwich
Copy link

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!

@TeXitoi TeXitoi added the bug This is a BUG. The fix may be released in a patch version even if considered breaking label May 14, 2020
@TeXitoi
Copy link
Owner

TeXitoi commented May 15, 2020

Thanks for the clear report.

@pizzamig
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a BUG. The fix may be released in a patch version even if considered breaking
Projects
None yet
Development

No branches or pull requests

3 participants