-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
WIP: switch to clap #5129
WIP: switch to clap #5129
Conversation
I'm just curious, I noticed you talking to someone on IRC last week about this...is there any desire to allow users of cargo-the-library to be able to reuse some of the argument code (I think the example was to help rustfmt behave the same for -p/--all/--exclude behavior)? Also, please let me know if you are interested in any help with this little project. |
This is plausible, though I think we should first just clean up the argument parsing inside Cargo itself, and only then think about extracting it as a crate. |
This seems plausible to me! For the WIP though would it be possible to delete |
It's not super trivial to do this exactly: ideally, you'd route What I've checked is that there's no regression1 for happy cases for There are some "regressions" for bad command lines cases in that clap gives better error messages :) I have not tried adding support for external commands and aliases yet, I expect these might cause some troubles. However, I am sure that "passes Cargo test suite" is not enough to guarantee exactly same parsing of arguments for all cases. But, hopefully, it'll be good enough for practical purposes! 1. except for a single weird regression in |
Ok no worries if it's not lossless just yet. I'm still more than happy to go in this direction! One suggestion I might have is to define a helper method on the trait for something like "standard set of build-related flags" which automatically implies things like frozen, locked, color, etc. That way adding a new flag to all subcommands is in theory one line-ish. |
This is more or less exactly what I am doing here, in the
Yep, that's precisely the intention! |
I'll close the PR for now so as to save CI machines from useless work. Will reopen when this is nearer to completion! |
Current status: I've ported existing subcomands over to clap, the diff is |
Clap Reopening of #5129 So, looks like all tests are 🍏 on my machine! I definitely want to refactor it some more, and also manually checked that we haven't regressed any help messages, but all the major parts are in place already.
This PR is a proof-of-concept for rewrite of Cargo's argument parsing from docopt into clap (the previous episode).
Only two commands (bench and build) are ported over to clap, and the code is of "prototype" quality :) However, I'd love to get general feedback about the general approach before moving forward with implementation.
The main problem which this aims to solve is excessive code duplication between various Cargo commands. In particular, when commands share some options (which often is the case!) each command has to repeat code, responsible for handling of these options. Annoyingly, the options are almost, but not quite, the same: for example, different commands have different descriptions of options ("test all packages" vs "benchmark all packages").
This actually makes quite difficult to use something like
structopt
orclap-derive
for the task, so I've decided to go with the usual stringly-typed approach of clap.The idea is to have a giant
clap::App
with all build-in subcommands, share definitons of options by providing.arg_color()
-like extensions for defining options, and share code by providingfn worksapce_from_options(args: &ArgMatches)
-like functions. Although only two commands,build
andbench
, are ported, they do share a significant chunk of code.Why we might want to do switch to clap:
Why we might want to maintain the status quo (docopt):
👏 👏 👏
r? @alexcrichton