From 5a78eb202e269902089b8454a5796cbf6c1b2900 Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Sun, 29 May 2016 22:06:20 +0200 Subject: [PATCH] Fix more opts. --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index f3375c7..9f7a5f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,24 +14,32 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian}; fn main() { let args: Vec = 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();