Skip to content

Commit

Permalink
Refactor --keep into Args::Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nil committed Jan 16, 2024
1 parent 8382f75 commit f557d4e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/command/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub struct Sample {
#[arg(long)]
pub min_samples: Option<u64>,

/// Keep temporary files after exiting.
#[arg(long)]
pub keep: bool,

/// Directory to store temporary sample data in.
/// Defaults to using the input's directory.
#[arg(long, env = "AB_AV1_TEMP_DIR")]
Expand Down
7 changes: 0 additions & 7 deletions src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ pub struct Args {
#[arg(long)]
pub crf_increment: Option<f32>,

// TODO refactor into Samples ArgGroup
/// Keep temporary files after exiting.
#[arg(long)]
pub keep: bool,

/// Enable sample-encode caching.
#[arg(
long,
Expand Down Expand Up @@ -130,7 +125,6 @@ pub async fn run(
thorough,
sample,
quiet,
keep,
cache,
vmaf,
}: &Args,
Expand All @@ -152,7 +146,6 @@ pub async fn run(
args: args.clone(),
crf: 0.0,
sample: sample.clone(),
keep: *keep,
cache: *cache,
stdout_format: sample_encode::StdoutFormat::Json,
vmaf: vmaf.clone(),
Expand Down
6 changes: 1 addition & 5 deletions src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ pub struct Args {
#[clap(flatten)]
pub sample: args::Sample,

/// Keep temporary files after exiting.
#[arg(long)]
pub keep: bool,

/// Enable sample-encode caching.
#[arg(
long,
Expand Down Expand Up @@ -87,7 +83,6 @@ pub async fn run(
args,
crf,
sample: sample_args,
keep,
cache,
stdout_format,
vmaf,
Expand All @@ -103,6 +98,7 @@ pub async fn run(
let duration = input_probe.duration.clone()?;
let input_fps = input_probe.fps.clone()?;
let samples = sample_args.sample_count(duration).max(1);
let keep = sample_args.keep;
let temp_dir = sample_args.temp_dir;

let (samples, sample_duration, full_pass) = {
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ async fn main() -> anyhow::Result<()> {
}

impl Command {
// IMPORTANT: All clauses mentioned explicitly to enforce keeping this
// in sync with the list of commands that expose args::Sample.
fn keep_temp_files(&self) -> bool {
match self {
Self::SampleEncode(args) => args.keep,
Self::CrfSearch(args) => args.keep,
_ => false,
Self::SampleEncode(args) => args.sample.keep,
Self::CrfSearch(args) => args.sample.keep,
Self::AutoEncode(args) => args.search.sample.keep,
Self::Vmaf(_) => false,
Self::Encode(_) => false,
Self::PrintCompletions(_) => false,
}
}
}

0 comments on commit f557d4e

Please sign in to comment.