summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2015-01-25 13:21:30 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2015-01-25 13:21:30 +0100
commit04f3bc7902f0eba88213ef418cfdfb7f325ec297 (patch)
tree80cd4547b242169ca40d0194fffdfad537ef909d
parent1af4f53013c1b3b57ef9eab0075b5fb03762e8a4 (diff)
downloadvtcol-04f3bc7902f0eba88213ef418cfdfb7f325ec297.tar.gz
vtcol.rs: add usage and improve validity check
-rw-r--r--vtcol.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/vtcol.rs b/vtcol.rs
index be3081a..acf8db7 100644
--- a/vtcol.rs
+++ b/vtcol.rs
@@ -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