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

version = expr ignored when using structs in subcommands #394

Closed
ajeetdsouza opened this issue May 29, 2020 · 3 comments
Closed

version = expr ignored when using structs in subcommands #394

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

Comments

@ajeetdsouza
Copy link

ajeetdsouza commented May 29, 2020

structopt ignores explicitly set version numbers when used on a struct inside an enum.

To reproduce:

#[derive(StructOpt)]
enum App {
    Baz(Baz),
}

#[derive(StructOpt)]
#[structopt(about = "testing", version = "v1337")]
struct Baz {}

Now running cargo run -- help baz gives us:

foo-baz 0.1.0
testing

USAGE:
    foo baz

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

This is unexpected, since structopt ignores the version field, but uses the about field.

Related issues:

@CreepySkeleton CreepySkeleton added the bug This is a BUG. The fix may be released in a patch version even if considered breaking label Jul 8, 2020
@CreepySkeleton
Copy link
Collaborator

This isn't really a bug. The trick is that you need to annotate the variants, not the underlying struct: the attrs on it aren't used. This is a pretty common mistake people make with doc comments.

use structopt::StructOpt;

#[derive(StructOpt)]
enum App {
    #[structopt(about = "testing", version = "v1337")]
    Baz(Baz),
}

#[derive(StructOpt)]
struct Baz {}

fn main() {
    App::from_args();
}
probe.exe-baz v1337
testing

USAGE:
    probe.exe baz

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

@ajeetdsouza
Copy link
Author

@CreepySkeleton true, but in the example I provided, the about field does work, despite the fact that it has been annotated on the struct and not the variant.

This is inconsistent behaviour, since the version field that has been annotated in the same place doesn't work.

@CreepySkeleton
Copy link
Collaborator

the about field does work

Yes, and it mustn't. This causes #391.

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

2 participants