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

Cargo: Build CLAP command using derive #213

Merged
merged 2 commits into from
Aug 13, 2023

Conversation

xFrednet
Copy link
Member

@xFrednet xFrednet commented Aug 6, 2023

Just a simple refactoring. At first, I was a bit hesitant, but I believe that this is the better way to handle Marker's CLI. Only the --test-setup argument changed into a hidden subcommand, the rest should be the same as before.

Nothing more to say otherwise. Reviews are appreciated. For everyone reading this, have a beautiful day! :D

@xFrednet xFrednet added C-enhancement Category: New feature or request A-marker-cargo Area: All things connected to `cargo_marker` S-waiting-on-review Status: Awaiting review labels Aug 6, 2023
@xFrednet xFrednet added this to the v0.2.0 milestone Aug 6, 2023
Copy link
Contributor

@NathanFrasier NathanFrasier left a comment

Choose a reason for hiding this comment

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

Tested locally, looks good to me functionality wise, a few small items to polish before merge though.

cargo-marker/src/cli.rs Outdated Show resolved Hide resolved
cargo-marker/src/main.rs Outdated Show resolved Hide resolved
@xFrednet
Copy link
Member Author

xFrednet commented Aug 9, 2023

Good catches, thank you very much for the review!

You can merge this PR by commenting bors r+ if you think this version is ready. I don't want to put pressure on you. It's totally fine if you would rather not give it another review or merge it :)

bors delegate=NathanFrasier

@bors
Copy link
Contributor

bors bot commented Aug 9, 2023

✌️ NathanFrasier can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

cargo-marker/src/cli.rs Outdated Show resolved Hide resolved
cargo-marker/src/cli.rs Outdated Show resolved Hide resolved
let backend_conf = backend::Config {
dev_build: flags.dev_build,
dev_build: cfg!(debug_assertions),
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC there are several places where dev build flag influences the discovery of the toolchain and driver.

I'd prefer if there was a magic env variable e.g. MARKER_DEV_MODE=1 that could be used for conditions when a dev mode is used. This wouldn't require building in release or changing code temporarily to [de]activate the dev mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of this change was to have a unified way across the entire project to enter dev mode. Having an environment value could work, but would be a bit weird, as it would always need to be set when interacting with the project. Or am I missing another option I'm missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you are right. Maybe MARKER_RELEASE_MODE could then be used as an override to opt out.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like it's too easy for a user to accidentally install it without setting the environment value.

cargo-marker/src/cli.rs Outdated Show resolved Hide resolved
cargo-marker/src/cli.rs Outdated Show resolved Hide resolved
cargo-marker/src/cli.rs Show resolved Hide resolved
@xFrednet
Copy link
Member Author

I want to combine the two review commits, before the merge. I'll wait a bit more for more feedback :)

Copy link
Contributor

@Veetaha Veetaha left a comment

Choose a reason for hiding this comment

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

I happened to stumble upon a project called cargo-nextest. It also uses clap derive for its CLI. That project doesn't make a special case for running cargo-nextest directly. It requires you to specify cargo-nextest nextest as a subcommand (CLI code). Maybe that code could be helpful

assert!(matches!(cli.command, Some(CliCommand::Check(_))));

let cli = MarkerCli::parse_from(&["cargo-marker"]);
assert!(matches!(cli.command, None));
Copy link
Contributor

@Veetaha Veetaha Aug 12, 2023

Choose a reason for hiding this comment

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

I think you may want an assert_maches crate. expect_test could also fit

Copy link
Member Author

Choose a reason for hiding this comment

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

The assert_maches link points to the CLI code of next test and I can't find the create on crates.io

Something like this would definitely be useful. You already mentioned this in a previous PR and #202 exists to investigate it. I would rather not add it in this PR, to keep it more contained, but this would be a great application for it 👍 (I just need time to get through all the issues 😅 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, an apology for the typo. It's assert_matches

Copy link
Member Author

Choose a reason for hiding this comment

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

I think expect_test would be a better fit here, mostly because it allows automatic test updates. Still, I won't add it in this PR. My next weeks will be more busy, and I want to make sure this and the other stuff is added before 0.2.0.

@xFrednet
Copy link
Member Author

I happened to stumble upon a project called cargo-nextest. It also uses clap derive for its CLI. That project doesn't make a special case for running cargo-nextest directly. It requires you to specify cargo-nextest nextest as a subcommand (CLI code). Maybe that code could be helpful

I really like this idea, thank you for the suggestion!

@xFrednet
Copy link
Member Author

I've squashed the review commits, this should not be ready to be merged.

bors r=Veetaha

@bors
Copy link
Contributor

bors bot commented Aug 13, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit d3b59f9 into rust-marker:master Aug 13, 2023
6 checks passed
@xFrednet xFrednet deleted the 213-derive-clap branch August 18, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-marker-cargo Area: All things connected to `cargo_marker` C-enhancement Category: New feature or request S-waiting-on-review Status: Awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants