From 869c7cb98b94d68154c38d5e45e45feb7472f42c Mon Sep 17 00:00:00 2001 From: moznion Date: Sat, 28 Nov 2020 17:35:56 +0900 Subject: [PATCH] Show usage for code_gen --- src/bin/code_gen.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/code_gen.rs b/src/bin/code_gen.rs index 0657048..040a79a 100644 --- a/src/bin/code_gen.rs +++ b/src/bin/code_gen.rs @@ -53,7 +53,7 @@ impl FromStr for RadiusAttributeValueType { } fn print_usage(program: &str, opts: &Options) { - let brief = format!("Usage: {} FILE [options]", program); + let brief = format!("Usage: {} [options] DICT_FILE OUT_FILE", program); print!("{}", opts.usage(&brief)); process::exit(0); } @@ -68,13 +68,18 @@ where fn main() { let args: Vec = env::args().collect(); - let _program = args[0].clone(); + let program = args[0].clone(); - let opts = Options::new(); + let mut opts = Options::new(); + opts.optflag("h", "help", "print this help menu"); let matches = opts .parse(&args[1..]) .unwrap_or_else(|f| panic!(f.to_string())); + if matches.opt_present("h") { + print_usage(&program, &opts); + } + let dict_file_path = Path::new(&matches.free[0]); if !dict_file_path.exists() { panic!("no such dictionary file => {}", &matches.free[0]);