You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm dynamically populating a Command, based on the contents of a struct. Because it's happening dynamically, I'm using the try versions of the getters on ArgMatches, to handle the case where things happened incorrectly. However, there's no try version of get_flag, which I use for my bool fields.
Describe the solution you'd like
Would like to have a fallible try_get_flag on ArgMatches, to compliment all of the other try_ versions of things. Currently there's no panic-free way to get an argument that you're expecting to be a SetTrue.
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Is there a reason you aren't using try_get_one? get_flag is just a convenience helper for get_one. I lean towards people using try_get_one when they need more rather than adding many variants of helpers (also not a fan of all of the get_matches / parse helpers and been considering reducing those)
I thought (because of the one) that try_get_one returns the value for an option that takes a single argument; that is, it returns Some when --arg value, None when --arg is omitted entirely, and an error otherwise. I haven't been able to find any precise documentation about the underlying "data model" used by ArgMatches; how it's populated from a Command, and specifically how the various get_* and try_get_* methods interpret the stored data.
In clap v3, flags were a special case without a value in ArgMatches, instead users having to check for its presence. In clap v4, we transition to always setting a value in ArgMatches, hence the names like SetTrue and SetFalse for flag ArgAction.
In fact, SetTrue is just a convenience helper for Set that implies
Please complete the following tasks
Clap Version
4.5
Describe your use case
I'm dynamically populating a
Command
, based on the contents of a struct. Because it's happening dynamically, I'm using thetry
versions of the getters onArgMatches
, to handle the case where things happened incorrectly. However, there's notry
version ofget_flag
, which I use for my bool fields.Describe the solution you'd like
Would like to have a fallible
try_get_flag
onArgMatches
, to compliment all of the othertry_
versions of things. Currently there's no panic-free way to get an argument that you're expecting to be aSetTrue
.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: