forked from bonsai/harakit
fop(1): committing to Rust error messages
This commit is contained in:
parent
448211bbe2
commit
3cee3de900
34
src/fop.rs
34
src/fop.rs
@ -18,7 +18,7 @@
|
||||
|
||||
use std::{
|
||||
env::args,
|
||||
io::{ Read, stdin, Write },
|
||||
io::{ Read, stdin, stdout, Write },
|
||||
process::{ Command, exit, Stdio },
|
||||
};
|
||||
|
||||
@ -54,8 +54,8 @@ fn main() {
|
||||
exit(EX_USAGE);
|
||||
});
|
||||
|
||||
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|_| {
|
||||
eprintln!("{}: {}: Not an integer.", argv[0], argv[1]);
|
||||
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|e| {
|
||||
eprintln!("{}: {}: {}.", argv[0], argv[1], e);
|
||||
exit(EX_DATAERR);
|
||||
});
|
||||
|
||||
@ -74,8 +74,8 @@ fn main() {
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap_or_else( |_| {
|
||||
eprintln!("{}: {}: Command not found.", argv[0], argv[command_arg]);
|
||||
.unwrap_or_else( |e| {
|
||||
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||
exit(EX_UNAVAILABLE);
|
||||
});
|
||||
|
||||
@ -83,7 +83,7 @@ fn main() {
|
||||
eprintln!(
|
||||
"{}: {}: No such index in input.",
|
||||
argv[0],
|
||||
index.to_string()
|
||||
index.to_string(),
|
||||
);
|
||||
exit(EX_DATAERR);
|
||||
});
|
||||
@ -93,11 +93,8 @@ fn main() {
|
||||
drop(child_stdin);
|
||||
}
|
||||
|
||||
let output = spawned.wait_with_output().unwrap_or_else(|_| {
|
||||
eprintln!("{}: {}: Command has no output.",
|
||||
argv[0],
|
||||
argv[command_arg]
|
||||
);
|
||||
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
||||
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||
exit(EX_IOERR);
|
||||
});
|
||||
|
||||
@ -105,16 +102,17 @@ fn main() {
|
||||
|
||||
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
||||
|
||||
let new_field = String::from_utf8(replace).unwrap_or_else(|_| {
|
||||
eprintln!(
|
||||
"{}: {}: Command output is invalid UTF-8.",
|
||||
argv[0],
|
||||
argv[command_arg]
|
||||
);
|
||||
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
||||
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||
exit(EX_IOERR);
|
||||
});
|
||||
|
||||
fields[index] = &new_field;
|
||||
|
||||
print!("{}", fields.join(&d.to_string()));
|
||||
stdout().write_all(
|
||||
fields.join(&d.to_string()).as_bytes()
|
||||
).unwrap_or_else(|e|{
|
||||
eprintln!("{}: {}.", argv[0], e);
|
||||
exit(EX_IOERR);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user