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

Migrate to Clap v4 #298

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Migrate to Clap v4 #298

wants to merge 1 commit into from

Conversation

dbrgn
Copy link
Owner

@dbrgn dbrgn commented Oct 22, 2022

Again, this is a pretty big update with multiple breaking changes that requires changing how our argument parsing is set up. (If I ignore the effort to upgrade, this update does contain some nice API improvements, so I guess in the long term it's worth it. The blogpost is an interesting read.)

This is still WIP, I'm opening this PR to avoid duplicate work on this.

@dbrgn
Copy link
Owner Author

dbrgn commented Feb 4, 2024

I think everything should work fine now, but the PR is currently blocked on #352.

Comment on lines +11 to +13
-p, --platform <PLATFORMS> Override the operating system [possible values: linux, macos, windows,
sunos, android]
Copy link
Owner Author

Choose a reason for hiding this comment

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

The help now doesn't list aliases anymore. I changed the code to use "macos" as main name and "osx" as alias (not vice versa), so that "macos" is shown in the help by default. "osx" still works though.

Copy link
Contributor

Choose a reason for hiding this comment

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

For it to show aliases, you now have to use visible_alias, if I recall correctly. You can have a mix of visible and invisible aliases.

Danilo Bargen <[email protected]>, Niklas Mohrin <[email protected]>
A fast TLDR client
Copy link
Owner Author

Choose a reason for hiding this comment

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

The default help output in clap now doesn't list version and author anymore.

I updated the help template to include those two again. The version is now combined with the description to get more compact output.

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Looks mostly good, some thoughts:

"Unknown color option: {}. Possible values: always, auto, never",
other
)),
impl clap::ValueEnum for ColorOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we be able to use the derive macro here? https://docs.rs/clap/latest/clap/_derive/_tutorial/chapter_3/index.html#enumerated-values (also for the other one above?)

long = "color",
value_name = "WHEN",
possible_values = ["always", "auto", "never"]
value_parser = EnumValueParser::<ColorOptions>::new(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to be so verbose here, we can use #[arg(value_enum)] or even not specify anything and clap will figure this out on its own (same for the other value enum)

Suggested change
value_parser = EnumValueParser::<ColorOptions>::new(),

)]
//possible_values = ["always", "auto", "never"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//possible_values = ["always", "auto", "never"]

after_help = "To view the user documentation, please visit https://dbrgn.github.io/tealdeer/."
#[command(
about = "A fast TLDR client",
version = "1.2.3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clap can read the version from Cargo.toml:

Suggested change
version = "1.2.3",
version,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants