-
Notifications
You must be signed in to change notification settings - Fork 119
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
base: main
Are you sure you want to change the base?
Migrate to Clap v4 #298
Conversation
I think everything should work fine now, but the PR is currently blocked on #352. |
-p, --platform <PLATFORMS> Override the operating system [possible values: linux, macos, windows, | ||
sunos, android] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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)
value_parser = EnumValueParser::<ColorOptions>::new(), |
)] | ||
//possible_values = ["always", "auto", "never"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//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", |
There was a problem hiding this comment.
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
:
version = "1.2.3", | |
version, |
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.