Replies: 4 comments 8 replies
-
One of the issues of your proposal (if I understand it correctly) is that all the inter-arg dependencies would be difficult to model. But this is actually a good start to the discussion. What do you think about parser plugins that actually do stuff while parsing and people can implement their own plugin to get desired effect? |
Beta Was this translation helpful? Give feedback.
-
A couple of I generally agree that we can (and should) do a better job of saying no to all feature requests and instead build something that can compose better and allow people to use those features to implement their desired functionality. A silly example I use is the original shell completions generating code. I designed and wrote that to a be a starting point for people to generate shell completions. I.e. you generate 90% of your shell completions and then tweak it to get your final script (i.e. iron out any oddities, or fix areas where we do something slightly different from the norm like not defaulting to local file globs on positional arguments*). (Un?)fortunately it worked well enough that people just used it. But since many wanted that last 5-10%, we got feature requests and bug reports to fix/support those edge cases, and sometimes it meant additions to the API in areas we didn't intend or think through fully so it feels bolted on.
|
Beta Was this translation helpful? Give feedback.
-
With Parser, Don't Validate, I was referring to the user parsing the This feature would replace and consolidate This would directly let us remove
For the user, this would
|
Beta Was this translation helpful? Give feedback.
-
My intention with
The most processing I had in mind was Maybe we start off with just making actions an Enum to gradually explore the API design. Even an |
Beta Was this translation helpful? Give feedback.
-
Looking at [NoAutoHelp](Inspired by https://github.com/clap-rs/clap/pull/2831/commits/1bb038a04fcb713bee03151e859f4ea6ea5cc625)s docs reminds me of a feeling that has been growing in me: that a part of clap's API surface and complexity stems from us allowing built-in machinery to be customized by end-users. I feel like we are hitting a local maxima with the approach we are taking and we need to re-evaluate this to keep clap's API and code base more approachable.
In general, I've been feeling like clap has a composability issue. Instead of new use cases falling out of the API design, we have to do things like support every combination of looking up a value (and we are missing a lot of "grouped" combinations).
I am always cautious of "I came from X, therefore they do it better" but I think we could simplify things with a couple of concepts from Python's
argparse
:ArgMatches
, it has a dumbNamespace
container that is effectively aHashMap<&str, Option<Box<Any>>>
and validation is replaced by parsingAllowInvalidUtf8
argparse.ArgumentParser.add_argument
accepts anaction
parameter to customize what happens when the argument is being processed. We only have support foraction="store"
with special-cases for--version
and--about
. What if we allow anaction
parameter that accepts afn(value, &App, &mut ArgMatches
?-h
and-V
, how help and version behave can be exposed as Actions for reuseoccurrences
being replaced by anappend
action.Namespace
, allows users to do value-grouping without any native support! Of course, we can look into upstreaming these kind of generally useful helpers.I fully admit this is all hand-waivy and there are a lot of details to work out. We might even be able to prototype this as a parallel to clap with the proposed modularization effort, like splitting out the lexer and creating a general reflection API that completion generation (and maybe even help output) are built on.
What are people's thoughts? This seem worth creating a roadmap to get to this over the next couple of major versions?
Beta Was this translation helpful? Give feedback.
All reactions