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

Update artichoke CLI to clap v4 #2196

Merged
merged 4 commits into from Sep 29, 2022
Merged

Conversation

lopopolo
Copy link
Member

@lopopolo lopopolo commented Sep 29, 2022

https://epage.github.io/blog/2022/09/clap4/

--help output is changed, so update the ui-test snapshots.

One of the neat new things in clap v4 is the ability to add a test to assert that the clap::Command is configured correctly. When a package has both a lib.rs and a binary target, I think #[test]s don't run in the main.rs, so this PR also takes the chance to migrate all of the artichoke clap CLI setup to a new artichoke::ruby::cli module.

@lopopolo lopopolo added A-deps Area: Source and library dependencies. A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. labels Sep 29, 2022
https://epage.github.io/blog/2022/09/clap4/

`--help` output is changed, so update the ui-test snapshots.
@lopopolo lopopolo force-pushed the lopopolo/artichoke-cli-clap-v4 branch from 07e4a0e to 3eca7b9 Compare September 29, 2022 01:53
src/ruby/cli.rs Outdated
Comment on lines 105 to 106
// (This is the point of this helper function. clap's functionality for
// doing this will panic on a broken pipe error.)
Copy link

Choose a reason for hiding this comment

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

I thought the broken pipe issue has been fixed for a while...

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 it has been, but this code has worked the whole time and doesn't have that much maintenance cost for me to carry. I also prefer having visibility into all calls to process::exit instead of having them happen in a library if I can help it.

Copy link
Member Author

Choose a reason for hiding this comment

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

But I can definitely clean up this comment since the clap side of things has been fixed.

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 just pushed a commit that removes this parenthetical comment. Thanks for catching that!

Copy link

Choose a reason for hiding this comment

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

You can also use err.print() so you can control the exiting but get clap to do the printing, including colored output. If you want more control over that and are fine with ANSI escape codes, you can now also call err.render().ansi().

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that's awesome!

Before

Screen Shot 2022-09-28 at 8 23 53 PM

After

Screen Shot 2022-09-28 at 8 24 06 PM

Copy link

Choose a reason for hiding this comment

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

Huh, noticed a couple issues in that. Addressed in clap-rs/clap#4287 which should be released soon

Copy link
Member Author

Choose a reason for hiding this comment

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

Glad to be of help!

This was fixed in 3.x.

Still keep the helper function, since it gives us control over the call to
process::exit and the exit code.
@lopopolo
Copy link
Member Author

Thanks for the code review @epage 🎉 ⚙️

@lopopolo lopopolo merged commit 44c721a into trunk Sep 29, 2022
@lopopolo lopopolo deleted the lopopolo/artichoke-cli-clap-v4 branch September 29, 2022 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-deps Area: Source and library dependencies. A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants