Minor code reformatings and adding missing arg shortcuts

This commit is contained in:
Jordi Boggiano 2014-01-07 01:35:24 +01:00
parent dfb68841fd
commit 01d426af01
2 changed files with 9 additions and 10 deletions

View file

@ -29,11 +29,10 @@ fn main() {
let args = ~os::args(); let args = ~os::args();
let opts = ~[ let opts = ~[
optflag("d", "decode", "decode data"), optflag("d", "decode", "decode data"),
optflag("i", "ignore-garbage", optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
"when decoding, ignore non-alphabetic characters"),
optopt("w", "wrap", optopt("w", "wrap",
"wrap encoded lines after COLS character (default 76, 0 to \ "wrap encoded lines after COLS character (default 76, 0 to disable wrapping)", "COLS"
disable wrapping)", "COLS"), ),
optflag("h", "help", "display this help text and exit"), optflag("h", "help", "display this help text and exit"),
optflag("V", "version", "output version information and exit") optflag("V", "version", "output version information and exit")
]; ];
@ -46,8 +45,7 @@ fn main() {
}; };
let progname = args[0].clone(); let progname = args[0].clone();
let usage = usage("Base64 encode or decode FILE, or standard input, to \ let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", opts);
standard output.", opts);
let mode = if matches.opt_present("help") { let mode = if matches.opt_present("help") {
Help Help
} else if matches.opt_present("version") { } else if matches.opt_present("version") {
@ -62,8 +60,7 @@ fn main() {
Some(s) => match from_str(s) { Some(s) => match from_str(s) {
Some(s) => s, Some(s) => s,
None => { None => {
error!("error: {:s}", "Argument to option 'wrap' \ error!("error: {:s}", "Argument to option 'wrap' improperly formatted.");
improperly formatted.");
fail!() fail!()
} }
}, },

View file

@ -41,8 +41,10 @@ fn options(args: &[~str]) -> Result<Options, ()> {
let opts = ~[ let opts = ~[
optflag("a", "append", "append to the given FILEs, do not overwrite"), optflag("a", "append", "append to the given FILEs, do not overwrite"),
optflag("i", "ignore-interrupts", "ignore interrupt signals"), optflag("i", "ignore-interrupts", "ignore interrupt signals"),
optflag("", "help", "display this help and exit"), optflag("h", "help", "display this help and exit"),
optflag("", "version", "output version information and exit")]; optflag("V", "version", "output version information and exit"),
];
getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| { getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| {
let version = format!("{} {}", NAME, VERSION); let version = format!("{} {}", NAME, VERSION);
let program = args[0].clone(); let program = args[0].clone();