fop(1): bring getopt(3) usage up-to-date
This commit is contained in:
parent
965d1bb76e
commit
6e4aeb7be7
19
src/fop.rs
19
src/fop.rs
@ -33,25 +33,20 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
||||
fn main() {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
let mut d = '\u{1E}'.to_string();
|
||||
let mut index_arg = 0;
|
||||
|
||||
let usage = format!(
|
||||
"Usage: {} [-d delimiter] index command [args...]",
|
||||
argv[0],
|
||||
);
|
||||
let mut index_arg = 0;
|
||||
let mut arg_parser = Parser::new(&argv, "d:");
|
||||
|
||||
while let Some(opt) = argv.getopt("d:") {
|
||||
match opt {
|
||||
Ok(o) => {
|
||||
match opt.opt() {
|
||||
Ok(_) => {
|
||||
/* unwrap because Err(OptError::MissingArg) will be returned if
|
||||
* o.arg is None */
|
||||
let arg = o.arg.clone().unwrap();
|
||||
let arg_char = arg.chars().collect::<Vec<char>>();
|
||||
if arg_char.len() > 1 {
|
||||
eprintln!("{}: {}: Not a character.", argv[0], arg);
|
||||
exit(EX_USAGE);
|
||||
} else { d = arg_char[0]; }
|
||||
index_arg = o.index();
|
||||
* opt.arg() is None */
|
||||
d = opt.arg().unwrap();
|
||||
index_arg = opt.ind();
|
||||
},
|
||||
Err(_) => {
|
||||
eprintln!("{}", usage);
|
||||
|
Loading…
Reference in New Issue
Block a user