diff --git a/src/main.rs b/src/main.rs index f8b7fbf..245e615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,22 @@ use nrgrip::metadata; use nrgrip::cue_sheet; use nrgrip::raw_audio; +const PRETTY_PROGNAME: &'static str = "NRGrip"; +const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); + +fn print_version() { + println!("{} v{}", PRETTY_PROGNAME, VERSION.unwrap_or("X.Y.Z")); +} + +fn print_usage(prog_name: &str, opts: &Options) { + let brief = format!("{prettyprog} - rip Nero Burning ROM audio images + +Usage: + {prog} [-icrx] [options] + {prog} [-h | -V]", prettyprog = PRETTY_PROGNAME, prog = prog_name); + + print!("{}", opts.usage(&brief)); +} fn main() { process::exit(main_main()); @@ -53,6 +69,8 @@ fn main_main() -> i32 { "extract the raw audio tracks"); opts.optflag("h", "help", "print this help message"); + opts.optflag("V", "version", + "print program version"); let options = match opts.parse(&args[1..]) { Ok(options) => options, @@ -67,6 +85,11 @@ fn main_main() -> i32 { return 0; } + if options.opt_present("version") { + print_version(); + return 0; + } + // Get input NRG image name if options.free.len() != 1 { // We need exactly one input file! @@ -129,13 +152,3 @@ fn main_main() -> i32 { 0 } - - -fn print_usage(prog_name: &str, opts: &Options) { - let brief = format!("NRGrip - rip Nero Burning ROM audio images - -Usage: - {prog} [-icrx] [options] - {prog} -h", prog = prog_name); - print!("{}", opts.usage(&brief)); -}