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

Display env variable in help text for flags #199

Closed
pacak opened this issue Apr 15, 2023 Discussed in #198 · 0 comments · Fixed by #200
Closed

Display env variable in help text for flags #199

pacak opened this issue Apr 15, 2023 Discussed in #198 · 0 comments · Fixed by #200

Comments

@pacak
Copy link
Owner

pacak commented Apr 15, 2023

Discussed in #198

Originally posted by gandro April 15, 2023
Thanks a lot for this wonderfully crafted crate, it's a pleasure to use.

I noticed that while switch() and flag() seem to support env variable fallback, the env variable is not shown in the help output as it is for arguments.

For a bit more context: In my application, I have two options. One allows the user to specify a font directory via path, the other one just tells the application to search for fonts in system directories. I want both options to be have an environment variable fallback, and this seems to work correctly (i.e. the env() call is functional). However, in the generated help output, the environment variable for the flag is not displayed, making it hard for users to discover the env fallback for the system-fonts option.

Here's are the two bpaf parsers:

let fonts_dir = long("fonts")
    .env("OIKOS_FONTS")
    .help("Load fonts from this directory")
    .argument::<PathBuf>("DIR")
    .optional();
let system_fonts = long("system-fonts")
    .env("OIKOS_SYSTEM_FONTS")
    .help("Search for additional fonts in system directories")
    .switch();

And here's the currently generated help output:

        --fonts <DIR>    [env:OIKOS_FONTS: N/A]
                         Load fonts from this directory
        --system-fonts   Search for additional fonts in system directories

Where I would love to be able to see something like this:

        --fonts <DIR>    [env:OIKOS_FONTS: N/A]
                         Load fonts from this directory
        --system-fonts   [env:OIKOS_SYSTEM_FONTS: N/A]
                         Search for additional fonts in system directories

Would something like this be possible?

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

Successfully merging a pull request may close this issue.

1 participant