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

Use clap builder instead of derive, restructure a bit to look like cargo #772

Merged
merged 4 commits into from
Aug 29, 2022

Conversation

cassaundra
Copy link
Contributor

This PR converts rm's arg parsing to clap builder with minimal changes to functionality. After this is merged, I will start working on using more cargo internals in the argument parsing, which will have more noticeable effects.

crates/cargo-rm/src/bin/cargo/commands/rm.rs Outdated Show resolved Hide resolved
crates/cargo-rm/src/bin/cargo/commands/rm.rs Show resolved Hide resolved
crates/cargo-rm/src/bin/cargo/commands/rm.rs Show resolved Hide resolved
crates/cargo-rm/src/bin/cargo/commands/rm.rs Outdated Show resolved Hide resolved
Comment on lines 111 to 117
let dev = args.contains_id("dev");
let build = args.contains_id("build");
let target = args.get_one("target").cloned();
let manifest_path = args.get_one("manifest_path").cloned();
let pkg_id = args.get_one("pkg_id");
let dry_run = args.contains_id("dry_run");
let quiet = args.contains_id("quiet");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please either use is_present or update the flags to ArgAction::SetTrue. Part of the intention of renaming is_present to contains_id is so that people can easily identify presence-check calls to update when porting from the old behavior to the new behavior

@cassaundra
Copy link
Contributor Author

I was going to push these fixes in a separate commit, but since they were so minor I just amended them to the last. Here are the latest changes as requested:

  • Use expect instead of unwrap in arg parsing
  • Own arg values wherever possible
  • Use bin_name("cargo")
  • Avoid contains_id by using ArgAction::SetTrue. I personally think this looks very clunky, so I'd be happy to have any feedback here
  • Use PathBufValueParser

Since we already have a value name DEP_ID, we should use a similar convention
for PKG_ID.
@epage
Copy link
Collaborator

epage commented Aug 29, 2022

I personally think this looks very clunky, so I'd be happy to have any feedback here

This is expected. iirc cargo has a help for it. The builder API is lower level than the derive, so I made the trade off for accessing bools to be clunky in favor of making them consistent with how everything else operates, letting them participate in all other clap features.

@epage epage merged commit 3632c33 into killercup:merge-rm Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants