Skip to content

Commit

Permalink
Rewrite argument parsing to use Clap's derives
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shssoichiro committed Jun 27, 2022
1 parent a8d1e46 commit a0f9c0f
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 566 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ dump_lookahead_data = ["byteorder", "image"]
arg_enum_proc_macro = "0.3"
bitstream-io = "1"
cfg-if = "1.0"
clap = { version = "3.1", optional = true, default-features = false, features = [
"color",
"std",
"wrap_help",
] }
clap = { version = "3.2.6", optional = true, default-features = false, features = ["color", "std", "wrap_help", "derive"] }
clap_complete = { version = "3", optional = true }
libc = "0.2"
y4m = { version = "0.7", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions src/api/config/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct EncoderConfig {
/// [`with_speed_preset()`]: struct.EncoderConfig.html#method.with_speed_preset
impl Default for EncoderConfig {
fn default() -> Self {
const DEFAULT_SPEED: usize = 6;
const DEFAULT_SPEED: u8 = 6;
Self::with_speed_preset(DEFAULT_SPEED)
}
}
Expand All @@ -130,7 +130,7 @@ impl EncoderConfig {
/// than 10, it will result in the same settings as 10.
///
/// [`from_preset()`]: struct.SpeedSettings.html#method.from_preset
pub fn with_speed_preset(speed: usize) -> Self {
pub fn with_speed_preset(speed: u8) -> Self {
EncoderConfig {
width: 640,
height: 480,
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/speedsettings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Default for SpeedSettings {

impl SpeedSettings {
/// Set the speed setting according to a numeric speed preset.
pub fn from_preset(speed: usize) -> Self {
pub fn from_preset(speed: u8) -> Self {
// The default settings are equivalent to speed 0
let mut settings = SpeedSettings::default();

Expand Down
4 changes: 2 additions & 2 deletions src/api/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;
use interpolate_name::interpolate_test;

fn setup_config(
w: usize, h: usize, speed: usize, quantizer: usize, bit_depth: usize,
w: usize, h: usize, speed: u8, quantizer: usize, bit_depth: usize,
chroma_sampling: ChromaSampling, min_keyint: u64, max_keyint: u64,
bitrate: i32, low_latency: bool, switch_frame_interval: u64,
no_scene_detection: bool, rdo_lookahead_frames: usize,
Expand Down Expand Up @@ -44,7 +44,7 @@ fn setup_config(
}

fn setup_encoder<T: Pixel>(
w: usize, h: usize, speed: usize, quantizer: usize, bit_depth: usize,
w: usize, h: usize, speed: u8, quantizer: usize, bit_depth: usize,
chroma_sampling: ChromaSampling, min_keyint: u64, max_keyint: u64,
bitrate: i32, low_latency: bool, switch_frame_interval: u64,
no_scene_detection: bool, rdo_lookahead_frames: usize,
Expand Down
Loading

0 comments on commit a0f9c0f

Please sign in to comment.