summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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