Clean up opts.

This commit is contained in:
2016-05-29 21:53:01 +02:00
parent 4815cd6817
commit 8d016c5196

View File

@@ -17,10 +17,8 @@ fn main() {
let mut opts = Options::new(); let mut opts = Options::new();
opts.optflag("c", "", "create file"); opts.optflag("c", "", "Compress file");
opts.optflag("x", "", "extract file"); opts.optflag("x", "", "Extract file");
opts.optopt("i", "", "input file", "NAME");
opts.optopt("o", "", "output file", "NAME");
let matches = match opts.parse(&args[1..]) { let matches = match opts.parse(&args[1..]) {
Ok(m) => { m } Ok(m) => { m }
@@ -28,14 +26,14 @@ fn main() {
}; };
if matches.opt_present("c") { if matches.opt_present("c") {
let input = matches.opt_str("i").unwrap(); let input = &matches.free[0];
let output = matches.opt_str("o").unwrap(); let output = &matches.free[1];
create(&input, &output); create(&input, &output);
} }
else if matches.opt_present("x") { else if matches.opt_present("x") {
let input = matches.opt_str("i").unwrap(); let input = &matches.free[0];
let output = matches.opt_str("o").unwrap(); let output = &matches.free[1];
extract(&input, &output) extract(&input, &output)
} }
@@ -59,11 +57,11 @@ fn create(input: &String, output: &String) {
} }
} }
let mut out : Vec<u8> = vec![]; let mut index : Vec<u8> = vec![];
out.write_i32::<LittleEndian>(i).unwrap(); index.write_i32::<LittleEndian>(i).unwrap();
output_file.write_all(&out).unwrap(); output_file.write_all(&index).unwrap();
} }
} }