|
|
|
@ -17,7 +17,7 @@ lazy_static! {
|
|
|
|
|
/// Print usage then exit with code `1`
|
|
|
|
|
pub fn usage() -> !
|
|
|
|
|
{
|
|
|
|
|
println!("Usage: {} [--rating <rating>] [<outputs...>]", &PROGRAM_NAME[..]);
|
|
|
|
|
println!("Usage: {} [--rating <rating>] [--number <number>] <output dir>]", &PROGRAM_NAME[..]);
|
|
|
|
|
println!("Usage: {} --help", &PROGRAM_NAME[..]);
|
|
|
|
|
|
|
|
|
|
std::process::exit(1)
|
|
|
|
@ -34,9 +34,7 @@ fn try_dir(path: impl AsRef<Path>) -> Result<config::OutputType, Error>
|
|
|
|
|
let path = path.as_ref();
|
|
|
|
|
if path.is_dir() {
|
|
|
|
|
Ok(config::OutputType::Directory(path.to_owned()))
|
|
|
|
|
} else if !path.exists() {
|
|
|
|
|
Ok(config::OutputType::File(path.to_owned()))
|
|
|
|
|
} else {
|
|
|
|
|
} else {
|
|
|
|
|
Err(Error::FileExists(path.to_owned()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -95,7 +93,7 @@ where I: IntoIterator<Item=String>
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum Error {
|
|
|
|
|
UnknownRating(String),
|
|
|
|
|
FileExists(PathBuf),
|
|
|
|
|
BadPath(PathBuf),
|
|
|
|
|
NoOutput,
|
|
|
|
|
|
|
|
|
|
Internal(Box<dyn error::Error>),
|
|
|
|
@ -110,7 +108,7 @@ impl fmt::Display for Error
|
|
|
|
|
match self {
|
|
|
|
|
Error::NoOutput => write!(f, "need at least one output, try `{} --help`", &PROGRAM_NAME[..]),
|
|
|
|
|
Error::UnknownRating(rating) => write!(f, "{} is not a valid rating", rating),
|
|
|
|
|
Error::FileExists(path) => write!(f, "file already exists: {:?}", path),
|
|
|
|
|
Error::BadPath(path) => write!(f, "directory does not exist, or is file: {:?}", path),
|
|
|
|
|
Error::Internal(bx) => write!(f, "internal error: {}", bx),
|
|
|
|
|
_ => write!(f, "unknown error"),
|
|
|
|
|
}
|
|
|
|
|