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 to clap 4 #5405

Merged
merged 9 commits into from May 15, 2023
Merged

Upgrade to clap 4 #5405

merged 9 commits into from May 15, 2023

Conversation

dlsmith
Copy link
Contributor

@dlsmith dlsmith commented May 13, 2023

Issue #5388

Summary of changes

  • Use Arg.num_args
  • Use Arg.value_parser
    • Replace Arg.possible_values
    • Remove use of Arg.allow_invalid_utf8, either parsing directly to PathBuf or OsString
    • Move custom parsing logic from usage to arg definition (e.g., usize)
  • Use ArgMatches.get_one and ArgMatches.get_many in place of ArgMatches.value_of* and ArgMatches.values_of*
  • Use new flag/option idioms
    • Arg.action(ArgAction::SetTrue) for flags
    • Replace ArgMatches.is_present with ArgMatches.get_flag for flags
    • Replace ArgMatches.is_present with ArgMatches.contains_id to check option presence
  • Remove use of App.trailing_var_arg
    • This was moved to Arg and now conflicts with last. See relevant unit test.

Copy link
Contributor

@bhansconnect bhansconnect left a comment

Choose a reason for hiding this comment

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

Looks great overall. Just a few minor comments.

.required(false);

let flag_prebuilt = Arg::new(FLAG_PREBUILT)
.long(FLAG_PREBUILT)
.help("Assume the platform has been prebuilt and skip rebuilding the platform\n(This is enabled by default when using `roc build` with a --target other than `--target <current machine>`.)")
.possible_values(["true", "false"])
.value_parser(["true", "false"])
Copy link
Contributor

Choose a reason for hiding this comment

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

While we are here, can we flip this to use .action(ArgAction::SetTrue) instead of true and false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it ok that it's not backward compatible? If so, happy to make the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the current implementation also allows you to opt out of the default behavior defined here, which we'd lose by switching to a bool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately, this flag will go away. So exactly how it works doesn't matter too much.

I think it should be fine to just make the inside of the first branch be true and the second branch stay the same. If that makes sense.

But no big deal either way, so feel free to not fix.

.help("The package's main .roc file")
.allow_invalid_utf8(true)
.num_args(0..0)
Copy link
Contributor

Choose a reason for hiding this comment

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

0 to 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I... do not know how that got there. Thanks for catching it.

Comment on lines 324 to 325
Arg::new(FLAG_TARGET)
.long(FLAG_TARGET)
.help("Choose a different target")
.default_value(Target::default().into())
.possible_values(Target::iter().map(|target| {
Into::<&'static str>::into(target)
}))
.default_value(Into::<&'static str>::into(Target::default()))
.value_parser(
PossibleValuesParser::new(
Target::iter().map(|target| {
Into::<&'static str>::into(target)
})
))
.required(false),
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is a bit complex, can we define it as a variable at the top and share it between all uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bhansconnect
Copy link
Contributor

bhansconnect commented May 14, 2023 via email

@dlsmith dlsmith marked this pull request as ready for review May 15, 2023 00:31
bhansconnect
bhansconnect previously approved these changes May 15, 2023
@bhansconnect
Copy link
Contributor

Looks great! Thanks for dealing with this update.

- Remove `num_args` call that wasn't supposed to be there
- Factor out shared value parser with non-trivial init
With this change, it's no longer possible to cross-compile to any target
other than wasm.
auto-merge was automatically disabled May 15, 2023 16:32

Head branch was pushed to by a user without write access

@bhansconnect
Copy link
Contributor

bhansconnect commented May 15, 2023

I think you may need to search for prebuilt-platform= in the repo and update a few uses in tests/comments.

For comments/strings, just change uses of --prebuilt-platform=true to something like with --prebuilt-platform
and --prebuilt-platform=false to something like without --prebuilt-platform.

bhansconnect
bhansconnect previously approved these changes May 15, 2023
I think confy dependencies changes, so the sha needs to be updated

Signed-off-by: Anton-4 <17049058+Anton-4@users.noreply.github.com>
bhansconnect
bhansconnect previously approved these changes May 15, 2023
@@ -23,7 +23,7 @@ rustPlatform.buildRustPackage {
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"confy-0.5.1" = "sha256-3PQdz9W/uJd4CaUZdwAd2u3JJ100SFAoKLCFE6THRZI=";
"confy-0.5.1" = "sha256-KML/uoze2djsFhYk488QAtauethDaC+0aZ3q56yAhuY=";
Copy link
Contributor

Choose a reason for hiding this comment

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

General question: how does the sha change without changing the version?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering the same thing for a while. The sha is for the built result, not for the confy source. With this PR the changing of dependencies led to some changes in dependency resolution and serde was changed to 1.0.163, serde is a dependency for confy, so confy was changed.

@Anton-4
Copy link
Contributor

Anton-4 commented May 15, 2023

I'll look at the clippy failure

Signed-off-by: Anton-4 <17049058+Anton-4@users.noreply.github.com>
@dlsmith
Copy link
Contributor Author

dlsmith commented May 15, 2023

Thanks for the help, @Anton-4!

@bhansconnect bhansconnect merged commit d94b3f5 into roc-lang:main May 15, 2023
10 checks passed
@dlsmith dlsmith deleted the i5388 branch May 15, 2023 20:47
dlsmith added a commit to dlsmith/roc that referenced this pull request May 17, 2023
@dlsmith dlsmith mentioned this pull request May 17, 2023
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.

None yet

3 participants