fop(1): made checking argv better

This commit is contained in:
Emma Tebibyte 2023-12-28 22:42:05 -07:00
parent cb12a5b8fc
commit f89a686d3c
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -28,30 +28,20 @@ use sysexits::{ EX_DATAERR, EX_USAGE };
fn main() {
let argv = args().collect::<Vec<String>>();
let usage = format!("Usage: {} index command [args...]", argv[0]);
let index = match argv.get(1) {
Some(i) => {
i.parse::<usize>().unwrap_or_else(|_| {
eprintln!("{}: {}: Not an integer.", argv[0], i);
exit(1);
})
},
None => {
eprintln!("{}", usage);
argv.get(2).unwrap_or_else(|| {
eprintln!("Usage: {} index command [args...]", argv[0]);
exit(EX_USAGE);
},
};
});
let index = argv[1].parse::<usize>().unwrap_or_else(|_| {
eprintln!("{}: {}: Not an integer.", argv[0], argv[1]);
exit(EX_DATAERR);
});
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let mut fields = buf.split('␞').collect::<Vec<&str>>();
argv.get(2).unwrap_or_else(|| {
eprintln!("{}", usage);
exit(EX_USAGE);
});
let opts = argv.iter().clone().skip(3).collect::<Vec<&String>>();
let mut spawned = Command::new(argv.get(2).unwrap())