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

Make negatable flag name customisable #439

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

camh-
Copy link
Contributor

@camh- camh- commented Jul 24, 2024

Allow a value on the negatable tag to specify a flag name to use for
negation instead of using --no-<flag-name> as the flag.

e.g.

Approve bool `default:"true",negatable:"deny"`

This example will allow --deny to set the Approve field to false.

Add duplicate flag name detection for negatable flags.

Add a check for flags with the `negatable` option if the negative flag
conflicts with another tag, such as:

    Flag   bool `negatable:""`
    NoFlag bool

The flag `--no-flag` is ambiguous in this scenario.
Allow a value on the `negatable` tag to specify a flag name to use for
negation instead of using `--no-<flag-name>` as the flag.

e.g.

    Approve bool `default:"true",negatable:"deny"`

This example will allow `--deny` to set the `Approve` field to false.
}

flagString += fmt.Sprintf("%s--%s", short, name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Looks like it could give something like f--force

Copy link
Contributor Author

@camh- camh- Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short is either -X, (hyphen, flag, comma, space) , (four spaces) or "" (empty string). It is pre-formatted, not just the actual short flag. I could change the name from short to shortFmt or something if you prefer.

@alecthomas alecthomas merged commit 4ecb535 into alecthomas:master Sep 10, 2024
5 checks passed
@alecthomas
Copy link
Owner

Thanks Cam, sorry about the delay this slipped my mind!

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 this pull request may close these issues.

2 participants