Skip to content

How to create a global flag  #503

@ThorstenHans

Description

@ThorstenHans

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions