Allow end users to indicate that specific arguments may be ignored if not recognized #2354
Closed
2 tasks done
Labels
A-parsing
Area: Parser's logic and needs it changed somehow.
C-enhancement
Category: Raise on the bar on expectations
S-wont-fix
Status: Closed as there is no plan to fix this
Closing comment:
Make sure you completed the following tasks
request to file it as an issue, and one request for more info.
Here, then, is an issue with more info.
Describe your use case
My team distributes two binaries; one written in Python, and one in Rust
with Clap. The Python binary invokes the Rust binary. As we add new
options to the Rust binary, we can’t immediately teach the Python
binary to pass them, because the most recently released version of
the Rust binary would fail with an “unrecognized option” error.
Another use case, as discussed in #2314, involves rolling deployments.
You have a binary at v1.0.0 running in production. You add a flag to it,
but you can’t teach your your prod configs to pass the new flag, because
v1.0.0 will choke if given that flag. Instead, you can change the
configs to pass
--undefok=bar --bar=1
. On v1.0.0, this will donothing; once v1.1.0 is rolled out, the flag value will be honored.
If a project of yours is blocked on this feature, please, mention it explicitly.
Kind of: this would make developing my team’s project (TensorBoard)
notably easier, as noted in the above link, but we have workarounds.
Describe the solution you'd like
The Google flags system has a feature called
undefok
(read as“undefined OK”). If your binary
myprog
uses gflags, and you runthen:
myprog
knows about the--bar
option, it will interpret theoption as usual;
myprog
does not know about the--bar
option, then it willbe ignored. (Without
--undefok=bar
, this would be an error thatthere is no known flag by the name
bar
.)Note that supporting or passing
--undefok=bar
does not mean that youcan pass arbitrary unrecognized arguments:
--wat=3
would still be anerror.
I imagine that this could be implemented either as a new
AppSettings
:…or as an
ArgSettings
to allow customizing the magic nameundefok
:Alternatives, if applicable
One heavyweight alternative is to provide a mode in which arbitrary
unrecognized flags are permitted. But this carries too high a cost:
users who make a typo in an option name should be alerted, not have
their inputs silently ignored.
Additional context
IMHO, it’s okay if we need to require that
--undefok
precede theundefined arguments on the command line:
I also imagine that there might be issues distinguishing flags from
options. It’s okay with me if we need to require that any
undefok
options use the “stuck” form:
The text was updated successfully, but these errors were encountered: