Implement --version switch

This commit is contained in:
Matteo Cypriani 2018-05-04 21:06:06 +02:00
parent 88fc07a478
commit 924dd3c8c7
1 changed files with 23 additions and 10 deletions

View File

@ -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] <image.nrg>
{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] <image.nrg>
{prog} -h", prog = prog_name);
print!("{}", opts.usage(&brief));
}