-
Notifications
You must be signed in to change notification settings - Fork 253
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
Rewrite argument parsing to use Clap's derives #2962
Conversation
Looks prettier by far :) Thank you! |
Changing all occurrences of the speed preset from a |
I wonder if anyone is aware of an alternative to |
It looks like there is an example for generating completions with the derive API: https://github.com/clap-rs/clap/blob/master/clap_complete/examples/completion-derive.rs |
7714f6d
to
a0f9c0f
Compare
pub bitrate: Option<i32>, | ||
/// Speed level (0 is best quality, 10 is fastest). | ||
/// Speeds 10 and 0 are extremes and are generally not recommended. | ||
#[clap(long, short, value_parser = clap::value_parser!(u8).range(0..=10), default_value_t = 6, help_heading = "ENCODE SETTINGS", long_help = build_speed_long_help())] |
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(long, short, value_parser = clap::value_parser!(u8).range(0..=10), default_value_t = 6, help_heading = "ENCODE SETTINGS", long_help = build_speed_long_help())] | |
#[clap(long, short, value_parser = clap::value_parser!(u8).range(0..=10), default_value_t = 6, help_heading = "ENCODE SETTINGS", long_help = build_speed_long_help)] |
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.
Interesting. It actually failed to compile for me when I omitted the ()
and succeeded without. 😕 I'll try again and see if I'm crazy or my machine is.
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.
Yeah it turns out it's unrelated to the parens, it's complaining because with the serialize feature on, the method returns Option<String>
and it wants an Option<&str>
. Which, I'm not really sure how to make it an Option<&str>
because of lifetimes. 🤔
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.
This is fairly annoying since it would require a lazy_static.
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.
or once_cell as @Luni-4 pointed out :)
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.
Yep, it seems lazy_static
is used more for this reason
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.
Yeah, sorry, I meant to push up this change, this week has just been quite busy with IRL job. 🙂
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.
Should be working now. At least, it worked locally 😅
This is something that has been on the radar for a while, but the recent deprecation of everything from Clap 3.1 in Clap 3.2 has pushed our hand a bit to get it done now with the new best practices from Clap 3.2.
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.
Thank you!
Not really sure where these new clippy errors came from... but I guess I have to fix them. 😅 They seem unrelated to my changes. Edit: Oh, a new stable Rust was released on June 30 and somehow I missed it. |
This is something that has been on the radar for a while, but the recent
deprecation of everything from Clap 3.1 in Clap 3.2 has pushed our hand
a bit to get it done now with the new best practices from Clap 3.2.