Skip to content

Commit

Permalink
Print a proper error message if the input file does not exist (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro authored May 4, 2022
1 parent 3003f64 commit 7610b5c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions av1an-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,24 +519,23 @@ pub(crate) fn resolve_file_paths(path: &Path) -> anyhow::Result<Box<dyn Iterator
// TODO: to validate file extensions
// let valid_media_extensions = ["mkv", "mov", "mp4", "webm", "avi", "qt", "ts", "m2t", "py", "vpy"];

if path.is_file() {
Ok(Box::new(std::iter::once(path.to_path_buf())))
} else if path.is_dir() {
ensure!(path.exists(), "Input path {:?} does not exist. Please ensure you typed it properly and it has not been moved.", path);

if path.is_dir() {
Ok(Box::new(read_in_dir(path)?))
} else {
bail!("path {:?} is not a file or directory", path)
Ok(Box::new(std::iter::once(path.to_path_buf())))
}
}

/// Returns vector of Encode args ready to be fed to encoder
pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
let input_paths = &*args.input;

let inputs: Vec<PathBuf> = input_paths
.iter()
.flat_map(|input| resolve_file_paths(input))
.flatten()
.collect();
let mut inputs = Vec::new();
for path in input_paths {
inputs.extend(resolve_file_paths(path)?);
}

let mut valid_args: Vec<EncodeArgs> = Vec::with_capacity(inputs.len());

Expand Down

0 comments on commit 7610b5c

Please sign in to comment.