From 6e4aeb7be7615ea899d7ba234713e50a63cc0a20 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 23 Jun 2024 01:00:48 -0600 Subject: [PATCH] fop(1): bring getopt(3) usage up-to-date --- src/fop.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index 29f1522..91c8a72 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -33,25 +33,20 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); 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::>(); - 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);