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

Help text not shown when using doc comment on externalized subcommand #254

Closed
hampuslidin opened this issue Sep 7, 2019 · 7 comments
Closed
Labels
enhancement We would love to have this feature! Feel free to supply a PR need-design The concrete desing is uncertain, please get involved in the discussion before sending a PR

Comments

@hampuslidin
Copy link

I have a structure like this:

#[derive(Debug, StructOpt)]
#[structopt(name = "todo")]
/// A todo tool.
struct Todo {
    #[structopt(subcommand)]
    subcommand: Subcommand,
}

#[derive(Debug, StructOpt)]
enum Subcommand {
    New(New),
}

#[derive(Debug, StructOpt)]
/// Create a new task.
struct New {
    /// The title of the task.
    title: String,
}

Invoking cargo run -- help yields:

todo 0.1.0
A todo tool.

USAGE:
    todo <SUBCOMMAND>

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

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    new

It would be great if the doc comment on the externalized subcommand could be used as the help message, instead of having it by the enum cases. The same goes for using the about field in the structopt attribute.

@CreepySkeleton
Copy link
Collaborator

CreepySkeleton commented Sep 7, 2019

Try this

#[derive(Debug, StructOpt)]
enum Subcommand {
    /// Create a new task.
    New(New),
}

#[derive(Debug, StructOpt)]
struct New {
    /// The title of the task.
    title: String,
}

@hampuslidin
Copy link
Author

Thanks for your solution! I am leaning towards this approach now as well for other reasons, but there might be situations where it makes more sense to have the description tied to the defining struct, as to make the code documentation more clear. But maybe that is nitpicking ;)

@CreepySkeleton
Copy link
Collaborator

CreepySkeleton commented Sep 7, 2019

@TeXitoi I just realized that flatten doesn't work on enum variants while it should. Am I right? If I am - that's a bug introduced by me in #229, oops.

EDIT: Nope, not by me :)

EDIT2: Not a bug. It looks like...

@TeXitoi
Copy link
Owner

TeXitoi commented Sep 7, 2019

Can you provide an example and thé behavior you expect?

@hampuslidin
Copy link
Author

Sure. As a bare minimum example:

#[derive(Debug, StructOpt)]
#[structopt(name = "todo")]
/// A todo tool.
enum Todo {
    New(New),
}

#[derive(Debug, StructOpt)]
/// Create a new task
struct New {
    /// The title of the task
    title: String,
}

or

#[derive(Debug, StructOpt)]
#[structopt(name = "todo", about = "A todo tool.")]
enum Todo {
    New(New),
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Create a new task")]
struct New {
    #[structopt(about = "The title of the task")]
    title: String,
}

I would expect cargo run -- help to output:

todo 0.1.0
A todo tool.

USAGE:
    todo <SUBCOMMAND>

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

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    new     Create a new task

@CreepySkeleton
Copy link
Collaborator

We may make this possible by allowing #[flatten] on single-typed enum variants

@TeXitoi TeXitoi added enhancement We would love to have this feature! Feel free to supply a PR need-design The concrete desing is uncertain, please get involved in the discussion before sending a PR labels Sep 17, 2019
@CreepySkeleton
Copy link
Collaborator

Funny thing - this is exactly how things work now :) see #333

I'm also closing this since implementing this design variant would be breaking change and structopt is unlikely to have another minor release. It is also very unclear what we should do (and what we can do) if both of the comments are present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR need-design The concrete desing is uncertain, please get involved in the discussion before sending a PR
Projects
None yet
Development

No branches or pull requests

3 participants