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
{{ message }}
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
Something I've been thinking about for a while and mentioned in BurntSushi/ripgrep#809 is to add some additional functions which allow users to do something mid parse. From the linked issue:
The other way would involve something I've been thinking about, which is to provide companions to the validators, namely the ability to provide functions to Filter/Skip, Map, and Action arguments mid parse. These would do things such as do something potentially impure (Action), allow one to filter/skip values (Filter/Skip haven't decide on naming yet), or transform actual values themselves (Map) to be saved in the matches struct. These would all have access to the matches struct as it exists at that time, in order to perform decisions or possibly even mutate. I should say though that this method is further off and would not be available until v3 at the earliest (if ever, pending design and implementation, etc.).
However, now that I'm thinking about it, all three of those could actually be combined into a single Arg::custom_parse which accepts a function that takes the arg/value currently being parsed, and returns an Option<T> where None is skip this value (i.e. parse it as a different arg), or Some(T) is "save this to the matches" it could be the value as passed in, or it could be something different entirely (i.e. a map).
This could also require a few companion methods on the matches struct that allows mutation. I'd like to expose these on a newtype wrapper PartialMatches(ArgMatches) so as not to expose these mutation functions on a regular basis. Functions could be something like PartialMatches::remove_{value,arg}, PartialMatches::add_{value,arg}, etc. It would also have all the normal ArgMatches methods provided via a facade.
The text was updated successfully, but these errors were encountered:
Comment by Zooce Tuesday Jul 16, 2019 at 15:55 GMT
This is exactly what I'm looking for. I have a use case where I'd like to give the user the ability to abbreviate a positional argument if they want to. I could then use the custom_parse (or whatever) function to see if they did abbreviate, and if so, map it to the full argument.
Issue by kbknapp
Friday Feb 16, 2018 at 03:10 GMT
Originally opened as clap-rs/clap#1185
Something I've been thinking about for a while and mentioned in BurntSushi/ripgrep#809 is to add some additional functions which allow users to do something mid parse. From the linked issue:
However, now that I'm thinking about it, all three of those could actually be combined into a single
Arg::custom_parse
which accepts a function that takes the arg/value currently being parsed, and returns anOption<T>
whereNone
is skip this value (i.e. parse it as a different arg), orSome(T)
is "save this to the matches" it could be the value as passed in, or it could be something different entirely (i.e. amap
).This could also require a few companion methods on the matches struct that allows mutation. I'd like to expose these on a newtype wrapper
PartialMatches(ArgMatches)
so as not to expose these mutation functions on a regular basis. Functions could be something likePartialMatches::remove_{value,arg}
,PartialMatches::add_{value,arg}
, etc. It would also have all the normalArgMatches
methods provided via a facade.The text was updated successfully, but these errors were encountered: