-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Clap, from scratch re-write and redesign discussion #259
Comments
|
enum ArgMatches {
Flag(u8), // occurrences of the flag
Argument(Vec<CowStr>), // arguments provided
// doesn't need 'occurrences' as we have vec.len() already
// assert!(vec.len() % self.rules.values_collected == 0)
// Positional(Vec<CowStr>), // Just use Argument at this level
// SubCommand?
} |
I think there is over usage of We can easily provide macro for I am not sure about I think subcommands require more special treatment than "just a positional argument that eats the rest of the iterator" (what if two subcommands are specified?) |
@sru I find the current
As for two subcommands. Say like |
Updated gist, slightly less I might solve the 'short' vs 'long' issue with a map of shorts/longs to u8 indexes of a vector containing the matchers. |
@james-darkfox Yes, |
Yes. For implementing this, it is simply for each short we see. Call the handle function (lending it the iterator); then it may grab as many arguments as it needs. See the commented out code for the general gist. (Commented out because |
Noticed two typos in your question. |
@james-darkfox Ah yes, that was what I meant. |
@sru What is your preference for the handling of shorts and their arguments? |
Updated gist @sru The last test |
Updated checklist, and gist |
Updated gist |
type App(AppMeta, Vec<Foo>);
enum Foo {
Arg(ArgRule),
SubCommand(App),
} |
need @kbknapp... |
@sru Chained commands; I was thinking much like |
@james-darkfox Yes, I was also thinking of |
@sru :) |
@james-darkfox Are you talking about auto-completion as in the shell auto-autocompletion? If that's the case, I've been thinking about a way to easily take a Going forward to keep discussion and implementation focused I'm proposing we do the following:
I'm proposing we do these in that order because it appears to me we need some structure to this re-design and rebuild. EDIT 3: This means if box 1 isn't checked, we shouldn't be working on box 2. It's very easy to get side-tracked working on the latest and greatest new idea without implementing the "must haves" or doing so with an incomplete feature set in mind...which is how Most importantly if we don't have a full picture of the feature set 2.x will include we cannot make sound design decisions. Meaning certain choices are dictated by other features that must be present. An example of this is validators. And this is not picking on @sru , it's just a an example 😄 But validators as currently implemented in the 2.x branch will probably not work with global arguments (because of the need to clone args down through child subcommands). If we go at this re-design without first fully listing the features and capabilities of I just want to be clear that all current capability must be present in 2.x although some of it may be tweaked/modified/combined/etc. I'm not afraid to scrap any 2.x designs we come up with if we determine it's no better than 1.x. I want 2.x to be rock solid and something we're all extremely proud of. So let's not be afraid to break things and change things in 2.x. This is our chance to get things right, and set ourselves up for the future...but we need to do so correctly and not back step at all, unless a current feature is truly a mistake that should never have been 😄 See EDIT 1, 2, and 3 above |
@kbknapp I was talking about completion for As for the structure. Please free free to create the respective issue/threads. I also think we should have an IRC channel for private discussion and interactive design decisions. Dumping ideas and responding after often-hours via GitHub isn't quite so ideal. I've just created As I've mentioned in one of @sru's PRs, I have a number of things that I need to do and so I won't be able to contribute as much as I'd like; I should be freed up in a couple of months. 2.0 does not need to be released anytime too soon @kbknapp rock solid may not necessarily be correctly implemented. See git vs darcs and the suckless philosophy. In either case, the balance of science and engineering is what determines the result. Clap1.x is pretty solid, covering many edge cases; while clap2 avoids the need for edge cases through a stricter design. I mentioned git vs darcs because git is very rock solid, but not so well designed. While darcs is very well designed, and not yet as solid. I happen to be working on implementing the patch theory from darcs in rust for one of my projects. |
@james-darkfox 👍 to everything you said, I agree very much. I'll start idling in the orc when I can too, that's a good idea. |
|
I think yo-bot has some irc pinging ability as well, it's just not enabled right now. |
@kbknapp I am not sure how this will work out. Since we are virtually rewriting the library, it is difficult to separate breaking changes from non-breaking changes. I agree that clap2 should have almost all the functionality that current clap has and that we should be more wary of what features will be in the library. However, I think that categorizing by feature is not a good idea because as of right now, I think it should be divided into three big categories: implementation, tests, and documentations. tests and documentations will be fine with just checklists,and we could divide implementations by... implementation. |
@james-darkfox wow, irc channel, just saw. |
@sru to be clear, I'm ok with losing some functionality for a clean implementation so long as that's not functionality we want anyways. There are certain parts of My main goal that I'm trying to avoid is pulling features out for a clean implementation, only to add them back in later putting us right back where we started or in the same boat as 1.x. Once I get some time I'll sit down and look at the current feature set and decide what my personal priorities are and rank them similar to issues (i.e. "required", "want to have", "nice to have", "remove", etc.). This doesn't have to be the final list, just my own thoughts on the matter 😄 |
This kind of flag usually fails to parse with most arg parsers. I’d probably expect the same because its ambiguous somewhat, not really intuitive, doesn’t match previous parsers etc. Short flags should only take arguments if they’re last in a concatenation of arguments (in your case |
@nagisa 👍 I agreee |
This shorthand was a side affect for the method that I was using to quickly parse shorts. It would take more effort to prevent the shorthand. There is nothing really wrong with the shorthand, and will likely not be the advertised method from developers of some project. They would split things up naturally. |
@james-darkfox Some users of clap library might think it as "unexpected behavior" though. |
@sru Maybe so, but if clearly explained there isn't anything wrong with it? Speaking of behavior.. Anyone have any thoughts to either an environment variable, feature-gate, or simple function to dump the argument parsing result. Would be nice for troubleshooting parsing and clearly demonstrate how the configuration actually parses what the developer or users provide the program. |
Is this in the feature list? I just started using clap, and the structure seems very amenable to allowing completion. Though rather than generating an auto-completion file, I had been thinking of a special completion mode enabled by flag or env var. Completion mode would take a partial command line and offer a list of completions. The benefit is that the program can use runtime information to complete values for some args, eg drawing values out of a database. Either way, I think it's a really worthwhile feature. |
Yes it is....although I have created anew issue to track it since it's just been on the back burner. I've thought about doing like you said but what I'm leary of is including that functionality unconditionally in programs that don't need or care about it. Perhaps only compiling in that functionality only in debug mode? I need to think on this and am open to all suggestions :) |
I made this list according to what I think clap can be divided into, from the list of features above. First, I'd like to point out that "multiple occurence" and "multiple values" are separate things and should be emphasized so. Consider I think separating the meta data (authors, versions, and any extra information) from the actual parsing and match of argument is good idea because meta data isn't needed to parse arguments. If done right, I believe that clap can be modularized. For example, parser doing parser thing, meta data doing meta data thing and so on. This could give the consumer customization and control in the intermediate steps of clap. Of course, it would reduce the number of AppSettings as well. It is also important that these customizations have to come with sane defaults such that clap can run out of the box without much configuration. I typed this up at a whim, so I am not sure if deviates too much from what clap currently is. The details has to be ironed out before actually doing anything (as mentioned by @kbknapp), but I think this is a good start to look into which will be changed, same, or new. It was rather lengthy, I apologize :P |
@sru And you're very correct about multiple occurrences being different from multiple values. Your example is spot on. I also totally agree with your comments. The one thing I'd add is, I'm all for (and encourage) modularizing clap internally but don't necessarily want to modularize it too much externally (beyond To be clear, i do want to modularize things internally as best we can, and that's something I've started to slowly refactor in. And I am good with modularizing certain things on the public facing API when it's intuitive enough, and provides a significant advantage in one way or another. My goal is to keep the external public facing API as simple as possible. |
@kbknapp I agree that exposing something to public API should provide significant advantage, but I am ambivalent about the intuitiveness. For example, let's say there are three possible ways to print help (this is a silly example):
On to breaking changes. The most obvious breaking changes would be:
These would not be complete list of breaking changes because we do not have implementation yet, but they are guaranteed breaking changes, yes? On the sidenote, since, I am not able to go on IRC often and I don't have IRC bouncer, it is not an effective way to communicate for me. I noticed clap has gitter. Is it viable platform for communication? |
Have a path for localization and translation #380 |
@sru You can see in #372 what you listed is almost exactly what's happening (minus the SubCommand->Subcommand....which I agree with, but I'm trying to keep breaking changes minor-ish and it's more of a bike-sheddding thing anyways). But with the addition of decreasing the lifetime annotations in public types So everyone is tracking, I'll be putting out a 2x release shortly with these minor breaking changes, but ergonomic wins and a chance to clean up some cruft. This full re-design can still be discussed, and once some solid implementation happens it'll just be the next major release. I'm not scared of large version numbers 😄 Bottom line, continue with discussion and implementation, just cause 2x is coming out does not mean this thread is done! 😄 |
I think conversation has staled a bit on this. I'm preferring individual tracking issues related to re-designing components. So I'm closing this for now. |
👍 I feel like this thread served its purpose quite well :-) |
[Drafting; @kbknapp @sru please feel free to update this OP as you see fit. Please "create a lock" by posting a comment saying that you're editing - and then delete when done]
From: #259 (comment)
clap
features and capabilities in the OP (EDIT: This is already mostly done, but not quite complete. There are a few features missing, or some that should be broken down into further sub-sections. EDIT 2: Also, I'm speaking more about separating current features, from proposed features, from implementation details...currently it's all mixed into one list)clap
consumer standpoint...breaking changes)clap
2.x tracked by individual 2.x issues with this issue being the overarching 2.x discussion forum and overall tracking issueMatches
struct allowing things likematches.some_arg
fields instead of the currentmatches.value_of("some_arg")
)Current (ripped from the README) feature
-f
)--flag
)-fBgoZ
is the same as-f -B -g -o -Z
)-vvv
or-v -v -v
)myprog <file>...
)--
meaning, only positional arguments follow-o value
)--option value
--option=value
git add <file>
whereadd
is a sub-command ofgit
)clap
you can achieve this exact functionality from Rust'sOption<&str>.unwrap_or("some default")
method (orResult<T,String>.unwrap_or(T)
when using typed values)Current Implementation Details
(Something about the current design that needs attention)
Proposed
-f
)--flag
)-fBgoZ
is the same as-f -B -g -o -Z
)-vvv
or-v -v -v
)myprog <file>...
)--
meaning, only positional arguments follow-o value
)--option value
--option=value
-o value -o other_value
abbreviated to-o value other_value
-oo value other_value
. The one instance of-o
is too easily problematic.--option=val1,val2,val3
git add <file>
whereadd
is a sub-command ofgit
)Required by defaultRequired through consumer decision. No default. Macro uses[]
for optional and<>
for required.Proposed Implementation Details
RFCs
Naming change
Settings
The text was updated successfully, but these errors were encountered: