diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2015-01-25 13:21:30 +0100 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2015-01-25 13:21:30 +0100 |
commit | 04f3bc7902f0eba88213ef418cfdfb7f325ec297 (patch) | |
tree | 80cd4547b242169ca40d0194fffdfad537ef909d | |
parent | 1af4f53013c1b3b57ef9eab0075b5fb03762e8a4 (diff) | |
download | vtcol-04f3bc7902f0eba88213ef418cfdfb7f325ec297.tar.gz |
vtcol.rs: add usage and improve validity check
-rw-r--r-- | vtcol.rs | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -21,6 +21,7 @@ impl Job { -> Job { let argv = std::os::args(); + let this = argv[0].clone(); let opts = &[ getopts::optopt("s", "scheme", "predefined color scheme", "NAME"), getopts::optflag("h", "help", "print this message") @@ -31,21 +32,35 @@ impl Job { Err(f) => panic!(f.to_string()) }; let scheme = match matches.opt_str("s") { - None => Scheme::Default, + None => { + Job::usage(&this, opts); + panic!("no color scheme given, aborting") + }, Some (name) => { match name.as_slice() { "solarized" | "solarized_dark" | "sd" => Scheme::SolarizedDark, "solarized_light" | "sl" => Scheme::SolarizedLight, - _ => Scheme::Default + "default" | "normal" => Scheme::Default, + garbage => { + Job::usage(&this, opts); + panic!("unknown color scheme “{}”, aborting", garbage); + } } } }; Job { - this : argv[0].clone(), + this : this, scheme : scheme } } + fn + usage (this : &String, opts: &[getopts::OptGroup]) + { + let brief = format!("usage: {} [options]", this); + print!("{}", getopts::usage(brief.as_slice(), opts)); + } + } /* [impl Job] */ /* Rust appears to come with two wrappers for ``ioctl(2)``, but neither can be utilized for our |