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

How to create a global flag #503

Closed
ThorstenHans opened this issue Oct 11, 2021 · 3 comments
Closed

How to create a global flag #503

ThorstenHans opened this issue Oct 11, 2021 · 3 comments

Comments

@ThorstenHans
Copy link

I wanted to create a global debug flag, so that all sub-commands accept this flag. However, adding global = true turns my flag into an argument which requires a value.

From documentation, I don't see another way how I can turn a flag into a global flag. Any suggestions here?

struct FooBar {
    #[structopt(long, short, help = "Prints debug information", global = true, env = "STRINGS__DEBUG")]
    debug: bool,
    input: String,
    #[structopt(subcommand)]
    cmd: SubCommand
}

when executing with this configuration, and providing just --debug, the app fails with the following error:

error: The argument '--debug <debug>' requires a value but none was supplied
@TeXitoi
Copy link
Owner

TeXitoi commented Oct 11, 2021

That's not global fault, that's env that change your flag to option. There is no really any solution for this using structopt and clapv2, but clapv3 (in alpha stage) should propose a solution for this.

@epage
Copy link
Contributor

epage commented Oct 11, 2021

Don't know if we've solved every problem here but clap-rs/clap#2539 was closed by clap-rs/clap#2664

@ThorstenHans
Copy link
Author

🙏🏼 Thanks for pointing me to env.

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

3 participants