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 #3129

Closed
epage opened this issue Dec 9, 2021 · 5 comments
Closed

Subcommand hijacks parent's about #3129

epage opened this issue Dec 9, 2021 · 5 comments
Labels
A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies

Comments

@epage
Copy link
Member

epage commented Dec 9, 2021

Issue by CodeSandwich
Thursday May 14, 2020 at 09:35 GMT
Originally opened as TeXitoi/structopt#391


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!

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by TeXitoi
Friday May 15, 2020 at 06:55 GMT


Thanks for the clear report.

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by pizzamig
Monday Jul 20, 2020 at 21:41 GMT


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

@epage epage added A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies labels Dec 9, 2021
@epage
Copy link
Member Author

epage commented Dec 9, 2021

Is this a dup of #3127 ? Is it already fixed?

@pksunkara
Copy link
Member

Yeah, that's what I was wondering. Didn't you already fix this and #3127?

@epage
Copy link
Member Author

epage commented Dec 10, 2021

Confirmed, this is fixed

use clap::StructOpt;

/// The main thing
#[derive(StructOpt)]
struct Main {
    #[structopt(subcommand)]
    subcommand: Subcommand,
}

/// The subcommand
#[derive(StructOpt)]
enum Subcommand {
    A {},
}

fn main() {
    Main::from_args();
}
test-clap 

The main thing

USAGE:
    test-clap <SUBCOMMAND>

OPTIONS:
    -h, --help    Print help information

SUBCOMMANDS:
    a       
    help    Print this message or the help of the given subcommand(s)

@epage epage closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants