Fix more opts.

This commit is contained in:
2016-05-29 22:06:20 +02:00
parent 8d016c5196
commit 5a78eb202e

View File

@@ -14,24 +14,32 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
let mut opts = Options::new();
opts.optflag("c", "", "Compress file");
opts.optflag("x", "", "Extract file");
opts.optflag("c", "", "compress file");
opts.optflag("d", "", "decompress file");
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()) }
};
if matches.opt_present("help") {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
return;
}
if matches.opt_present("c") {
let input = &matches.free[0];
let output = &matches.free[1];
create(&input, &output);
compress(&input, &output);
}
else if matches.opt_present("x") {
else if matches.opt_present("d") {
let input = &matches.free[0];
let output = &matches.free[1];
@@ -39,7 +47,7 @@ fn main() {
}
}
fn create(input: &String, output: &String) {
fn compress(input: &String, output: &String) {
let mut output_file = fs::File::create(output).unwrap();
let input_file = fs::File::open(input).unwrap();