-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Args::Flag: Add required
attribute
#14087
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
base: master
Are you sure you want to change the base?
Conversation
if (flag->required && flag->timesUsed == 0) | ||
throw UsageError("required argument '--%s' is missing", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we list multiple such flags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there can be multiple required
flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I mean collect them all and throw error with all of them
|
||
// FIXME: this should be private, but that breaks designated initializers. | ||
size_t timesUsed = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really ugly that Flag
becomes mutable. Can we avoid this by storing the use-count separately? I would hope that Flag
stays an immutable description with a callback. Can't we instead track if the argument has been specified multiple times in the Handler
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I would prefer that too, thanks for catching @xokdvium
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a problem since Args
owns the Flags
anyway (i.e. it was already mutable).
Motivation
This allows specifying flags that are mandatory. The motivation was
nix nario export
(#13969), which has a required--format
flag.Note: The
timesUsed
counter could also be used to warn about flags being set multiple times (#13899).Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.