Fix a couple of todos.

This commit is contained in:
2016-06-07 19:26:43 +02:00
parent a18a709a76
commit d290f977d1
2 changed files with 35 additions and 24 deletions

View File

@@ -18,6 +18,11 @@ use pbr::{ProgressBar, Units};
mod bbp;
fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
}
fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
@@ -29,14 +34,28 @@ fn main() {
opts.optflag("h", "help", "display this help and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(f) => { panic!(f.to_string()) }
Ok(m) => m,
Err(_) => {
print_usage(&program, opts);
std::process::exit(1);
}
};
if matches.opt_present("help") {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
return;
print_usage(&program, opts);
std::process::exit(0);
}
if matches.free.len() == 1 {
println!("Missing operand: OUTPUT");
println!("Try `{} --help` for more information.", program);
std::process::exit(1);
}
if matches.free.len() == 0 {
println!("Missing operand: INPUT OUTPUT");
println!("Try `{} --help` for more information.", program);
std::process::exit(1);
}
if matches.opt_present("c") {
@@ -44,8 +63,7 @@ fn main() {
let output = &matches.free[1];
compress(&input, &output);
}
else if matches.opt_present("d") {
} else if matches.opt_present("d") {
let input = &matches.free[0];
let output = &matches.free[1];