Conversation
| if (flag->required && flag->timesUsed == 0) | ||
| throw UsageError("required argument '--%s' is missing", name); |
There was a problem hiding this comment.
Can we list multiple such flags?
There was a problem hiding this comment.
Yes, there can be multiple required flags.
There was a problem hiding this comment.
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.
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.
Yes I would prefer that too, thanks for catching @xokdvium
There was a problem hiding this comment.
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--formatflag.Note: The
timesUsedcounter 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.