fop(1): bring getopt(3) usage up-to-date

This commit is contained in:
Emma Tebibyte 2024-06-23 01:00:48 -06:00
parent 965d1bb76e
commit 6e4aeb7be7
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -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);