forked from bonsai/harakit
fop(1): made checking argv better
This commit is contained in:
parent
cb12a5b8fc
commit
f89a686d3c
26
src/fop.rs
26
src/fop.rs
@ -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]);
|
||||
argv.get(2).unwrap_or_else(|| {
|
||||
eprintln!("Usage: {} index command [args...]", argv[0]);
|
||||
exit(EX_USAGE);
|
||||
});
|
||||
|
||||
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);
|
||||
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())
|
||||
|
Loading…
Reference in New Issue
Block a user