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

Top level parser group_help breaks help message #319

Closed
ysndr opened this issue Nov 22, 2023 · 6 comments
Closed

Top level parser group_help breaks help message #319

ysndr opened this issue Nov 22, 2023 · 6 comments

Comments

@ysndr
Copy link
Contributor

ysndr commented Nov 22, 2023

When adding documentation group_help to the top level parser via a doc comment or the group_help` annotation, the generated help message becomes malformatted.
It appears as if the doc comments for fields of the parser are interpreted as general documentation:

/// commented command              << this line breaks things
#[derive(Bpaf)]
struct MyArgs {
    /// commended flag
    flag: bool,
}

fn main() {
    my_args().to_options().run();
}

without the parser comment:

Usage: flox [--flag]

Available options:
        --flag  commended flag
    -h, --help  Prints help information

with the parser comment:

Usage: prog [--flag]

commented command
        --flag  commended flag

Available options:
    -h, --help  Prints help information

with group_help

Usage: flox [--flag]

my_args help
        --flag  commended flag

Available options:
    -h, --help  Prints help information
@ysndr ysndr changed the title Top level parser docs break help message Top level parser group_help breaks help message Nov 22, 2023
@pacak
Copy link
Owner

pacak commented Nov 22, 2023

This is somewhat expected behavior. group_help adds a common header for several options. For example in cargo-show-asm I split options into several structs - to make it easier to use internally, this also groups them in --help output:

1

What kind of use case for group_help do you have in mind?

@ysndr
Copy link
Contributor Author

ysndr commented Nov 27, 2023

Let me try to elaborate, I think this is somewhat related to #290 as well

What I'm trying to do is to separate the rust doc comments from cli help.
IMO the doc comments are not helpful within rustdoc but i can't add rust doc comments.

thus, in the top-level parser i include groups and set group help either through rustdoc comment (or group_help if i dont particularly care about the rustdoc).
I'd like to do so on the group enum itself but group_help in that position seems to be ignored (#290)

However, this way there seems now no way to add a general description to the application as in adding headers and footers to the command.
When I add a doc comment or grouphelp to MyArgs here, the groups defined therein are getting messed up.

use bpaf::{Bpaf, Parser};

// /// commented command              << this line breaks things
#[derive(Bpaf)]
// #[bpaf(group_help("breaks stuff too"))]
struct MyArgs {
    /// commended flag
    flag: bool,

    /// primary group description (ignored)
    /// rustdoc comment
    #[bpaf(external(my_group))]
    primary_group: MyGroup,

    /// rustdoc comment
    #[bpaf(external(my_group2), group_help("secondary group description"))]
    secondary: MyGroup2,
}

/// Group of primary subcommands
#[derive(Bpaf, Clone)]
#[bpaf(group_help("primary group description"))] // ignored?
enum MyGroup {
    /// run command
    #[bpaf(command)]
    Run,
}

/// Group of primary subcommands
#[derive(Bpaf, Clone)]
enum MyGroup2 {
    /// build command
    #[bpaf(command)]
	// #[bpaf(help("description for command"))] // unavailable?
    Build,
}

fn main() {
    my_args().to_options().run();
}

@pacak
Copy link
Owner

pacak commented Nov 27, 2023 via email

@ysndr
Copy link
Contributor Author

ysndr commented Nov 27, 2023

Note it behaves differently if using #[bpaf(options)] on the top-level struct, more correctly🤔

@pacak
Copy link
Owner

pacak commented Nov 28, 2023

I added #[bpaf(ignore_rustdoc)] that you should be able to use at any place that accepts rustdoc comments, unreleased yet. Can you check if it solves your problem?

#321

@ysndr ysndr mentioned this issue Nov 29, 2023
@pacak
Copy link
Owner

pacak commented Dec 21, 2023

resolved in #321

@pacak pacak closed this as completed Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants