Skip to content
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

chore: Upgrade to clap 3.2 #10753

Merged
merged 3 commits into from
Jun 14, 2022
Merged

chore: Upgrade to clap 3.2 #10753

merged 3 commits into from
Jun 14, 2022

Conversation

epage
Copy link
Contributor

@epage epage commented Jun 13, 2022

I decided to use cargo as a test case for upgrading to clap 3.2 prior to release. From the builder API's perspective, a lot has change. While the changelog summarizes it, the release announcement is still pending. In short, the API is now typed. You declare what type an Arg is and access it by that type. flags (both is_present and occurrences_of) are also now specified through ArgAction and the result gets stored like any other arg value. I made a ArgMatchesExt::flag and command_prelude::flag functions to make working with these easier.

Now that clap exposes non-panicking variants of its functions, I switched from a "look before you leap" approach with is_arg_valid to a "better to ask forgiveness than permission" with checking the error variant. I decided to just make a convenience to swallow that error type. Not a fan of how loose things are but I think this will just be something we iterate on over time.

@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2022
@jonhoo jonhoo mentioned this pull request Jun 13, 2022
@Muscraft
Copy link
Member

It looks like this might still be needed for the CI to pass.

#10755 and #10754 both fail on i686-unknown-linux-gnu on the below test.

 ---- cargo_add::invalid_target_empty::invalid_target_empty stdout ----
thread 'cargo_add::invalid_target_empty::invalid_target_empty' panicked at '
---- expected: tests/testsuite/cargo_add/invalid_target_empty/stderr.log
++++ actual:   stderr
   1    1 | error: The argument '--target <TARGET>' requires a value but none was supplied
   2    2 | 
   3      - USAGE:
   4      -     cargo add [OPTIONS] <DEP>[@<VERSION>] ...
   5      -     cargo add [OPTIONS] --path <PATH> ...
   6      -     cargo add [OPTIONS] --git <URL> ...
   7      - 
   8    3 | For more information try --help

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I switched from a "look before you leap" approach with is_arg_valid to a "better to ask forgiveness than permission" with checking the error variant.

Sorry, I don't get it. How does this help?

@epage
Copy link
Contributor Author

epage commented Jun 14, 2022

Looks good!

I switched from a "look before you leap" approach with is_arg_valid to a "better to ask forgiveness than permission" with checking the error variant.

Sorry, I don't get it. How does this help?

Instead of is_valid_arg calls being made before accessing an arg, a lot of lower level calls do a strip out the MatchesError::UnknownArgument case.

We need to do something because any given cargo command may look up values for an arg that isn't defined because of how the code sharing works.

Having a lot of is_valid_arg checks at the call sites was annoying to manage though it is nicer for catching bugs though they are likely to be rare and caught through tests.

@weihanglo
Copy link
Member

Make sense. Thanks for the explanation. Going to merge this.

@bors r+

@bors
Copy link
Contributor

bors commented Jun 14, 2022

📌 Commit fc0ca1e has been approved by weihanglo

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 14, 2022
@bors
Copy link
Contributor

bors commented Jun 14, 2022

⌛ Testing commit fc0ca1e with merge 17f8088...

@bors
Copy link
Contributor

bors commented Jun 14, 2022

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 17f8088 to master...

@bors bors merged commit 17f8088 into rust-lang:master Jun 14, 2022
@epage epage deleted the clap32-deprecated branch June 15, 2022 15:13
arlosi added a commit to arlosi/rust that referenced this pull request Jun 17, 2022
4 commits in 4d92f07f34ba7fb7d7f207564942508f46c225d3..8d42b0e8794ce3787c9f7d6d88b02ae80ebe8d19
2022-06-10 01:11:04 +0000 to 2022-06-17 16:46:26 +0000
- Use specific terminology for sparse HTTP-based registry (rust-lang/cargo#10764)
- chore: Upgrade to clap 3.2 (rust-lang/cargo#10753)
- Improve testing framework for http registries (rust-lang/cargo#10738)
- doc: Improve example of using the links field (rust-lang/cargo#10728)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 18, 2022
Update cargo

4 commits in 4d92f07f34ba7fb7d7f207564942508f46c225d3..8d42b0e8794ce3787c9f7d6d88b02ae80ebe8d19
2022-06-10 01:11:04 +0000 to 2022-06-17 16:46:26 +0000
- Use specific terminology for sparse HTTP-based registry (rust-lang/cargo#10764)
- chore: Upgrade to clap 3.2 (rust-lang/cargo#10753)
- Improve testing framework for http registries (rust-lang/cargo#10738)
- doc: Improve example of using the links field (rust-lang/cargo#10728)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 18, 2022
Update cargo

4 commits in 4d92f07f34ba7fb7d7f207564942508f46c225d3..8d42b0e8794ce3787c9f7d6d88b02ae80ebe8d19
2022-06-10 01:11:04 +0000 to 2022-06-17 16:46:26 +0000
- Use specific terminology for sparse HTTP-based registry (rust-lang/cargo#10764)
- chore: Upgrade to clap 3.2 (rust-lang/cargo#10753)
- Improve testing framework for http registries (rust-lang/cargo#10738)
- doc: Improve example of using the links field (rust-lang/cargo#10728)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 18, 2022
Update cargo

4 commits in 4d92f07f34ba7fb7d7f207564942508f46c225d3..8d42b0e8794ce3787c9f7d6d88b02ae80ebe8d19
2022-06-10 01:11:04 +0000 to 2022-06-17 16:46:26 +0000
- Use specific terminology for sparse HTTP-based registry (rust-lang/cargo#10764)
- chore: Upgrade to clap 3.2 (rust-lang/cargo#10753)
- Improve testing framework for http registries (rust-lang/cargo#10738)
- doc: Improve example of using the links field (rust-lang/cargo#10728)
@ehuss ehuss added this to the 1.63.0 milestone Jun 22, 2022
ehuss added a commit to ehuss/cargo that referenced this pull request Jun 30, 2022
This is due to a change in clap 3.2. Cargo's CI runs without a lock
file, but rust-lang/rust runs with one (locked to an older version). To
avoid issues, this just ignores the test. See
rust-lang#10753 for more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants