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

Upgrade the clap CLI parsing crate to 4.5 #22088

Merged
merged 2 commits into from
Mar 13, 2025
Merged

Conversation

benjyw
Copy link
Contributor

@benjyw benjyw commented Mar 13, 2025

We were stuck on v3 for a long time, and were using
deprecatedAPIs removed in v4.

This allows us to finally upgrade the crate and hopefully
stay current with it going forward.

@benjyw benjyw added the release-notes:not-required PR doesn't require mention in release notes label Mar 13, 2025
@benjyw benjyw requested review from tdyas and huonw March 13, 2025 01:48
@benjyw
Copy link
Contributor Author

benjyw commented Mar 13, 2025

This was largely mechanical but also somewhat annoying to write and presumably to review. Sorry!

@@ -6,7 +6,7 @@ authors = ["Pants Build <[email protected]>"]
publish = false

[dependencies]
clap = { workspace = true }
clap = { workspace = true, features = ["string"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "string" feature allows default_value to take dynamic strings, which we use in a couple of places. Otherwise they must be &'static str...

.long("local-store-path")
.default_value_os(default_store_path.as_ref())
.default_value(Store::default_path().to_str().unwrap().to_string())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an example of a dynamic, owned default.

.required(false),
).arg(
Arg::new("server-address")
.takes_value(true)
.num_args(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.long("batch-api-size-limit")
.required(false)
.default_value("4194304")
)
.get_matches();

let mount_path = args.value_of("mount-path").unwrap();
let store_path = args.value_of("local-store-path").unwrap();
let mount_path = args.get_one::<String>("mount-path").unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tls_config,
headers,
chunk_size_bytes: 4 * 1024 * 1024,
timeout: std::time::Duration::from_secs(5 * 60),
retries: 1,
concurrency_limit: args
.value_of_t::<usize>("rpc-concurrency-limit")
.expect("Bad rpc-concurrency-limit flag"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These .expects are no longer needed - get_one() will panic appropriately already, with more information than this message provides...

@@ -86,8 +86,12 @@ async fn main() {
"Ingest a file by path, which allows it to be used in Directories/Snapshots. \
Outputs a fingerprint of its contents and its size in bytes, separated by a space.",
)
.arg(Arg::new("path").required(true).takes_value(true))
.arg(Arg::new("output-mode").long("output-mode").possible_values(["json", "simple"]).default_value("simple").multiple_occurrences(false).takes_value(true).help(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

multiple_occurrences is the default (or rather, it corresponds to ArgAction::Set, which is the default).

@benjyw
Copy link
Contributor Author

benjyw commented Mar 13, 2025

Note that we use both the programmatic and declarative APIs, in different main.rss - this covers changes to both.

@tdyas
Copy link
Contributor

tdyas commented Mar 13, 2025

This was largely mechanical but also somewhat annoying to write and presumably to review. Sorry!

Looks good to me. Thanks for doing this!

@benjyw benjyw merged commit f300c5b into pantsbuild:main Mar 13, 2025
24 checks passed
@benjyw benjyw deleted the upgrade_clap branch March 13, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:not-required PR doesn't require mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants