Clean up opts.
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -17,10 +17,8 @@ fn main() {
|
||||
|
||||
let mut opts = Options::new();
|
||||
|
||||
opts.optflag("c", "", "create file");
|
||||
opts.optflag("x", "", "extract file");
|
||||
opts.optopt("i", "", "input file", "NAME");
|
||||
opts.optopt("o", "", "output file", "NAME");
|
||||
opts.optflag("c", "", "Compress file");
|
||||
opts.optflag("x", "", "Extract file");
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => { m }
|
||||
@@ -28,14 +26,14 @@ fn main() {
|
||||
};
|
||||
|
||||
if matches.opt_present("c") {
|
||||
let input = matches.opt_str("i").unwrap();
|
||||
let output = matches.opt_str("o").unwrap();
|
||||
let input = &matches.free[0];
|
||||
let output = &matches.free[1];
|
||||
|
||||
create(&input, &output);
|
||||
}
|
||||
else if matches.opt_present("x") {
|
||||
let input = matches.opt_str("i").unwrap();
|
||||
let output = matches.opt_str("o").unwrap();
|
||||
let input = &matches.free[0];
|
||||
let output = &matches.free[1];
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user