diff options
author | Teddy Wing | 2020-09-17 01:58:12 +0200 |
---|---|---|
committer | Teddy Wing | 2020-09-17 02:01:17 +0200 |
commit | 664b4d1f0bca4891e06dc7a3cb179bed7a842bb1 (patch) | |
tree | e47a956d8b3b871b57bb5199ef5236186870f445 | |
parent | 9e910646a5c60007f10e8ea69a7120d50b4868e7 (diff) | |
download | git-todo-664b4d1f0bca4891e06dc7a3cb179bed7a842bb1.tar.bz2 |
main.rs: Add `-h` help flag
Print usage information with `-h`.
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 4d810b0..efe4477 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ fn main() { let args: Vec<String> = env::args().collect(); let mut opts = Options::new(); + opts.optflag("h", "help", "print this help menu"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -22,6 +23,11 @@ fn main() { }, }; + if matches.opt_present("h") { + print_usage(&opts); + process::exit(exitcode::USAGE); + } + let repo = match Repository::open(".") { Ok(r) => r, Err(e) => { @@ -70,6 +76,12 @@ fn main() { }; } +/// Print command line usage. +fn print_usage(opts: &Options) { + let brief = "usage: git todo [<commit>]"; + print!("{}", opts.usage(&brief)); +} + /// Print to standard error with a program-specific prefix. fn eprintln<D: std::fmt::Display>(error: &D) { eprintln!("error: {}", error); |