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::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
io::{ Read, stdin, Write },
|
io::{ Read, stdin, stdout, Write },
|
||||||
process::{ Command, exit, Stdio },
|
process::{ Command, exit, Stdio },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,8 +54,8 @@ fn main() {
|
|||||||
exit(EX_USAGE);
|
exit(EX_USAGE);
|
||||||
});
|
});
|
||||||
|
|
||||||
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|_| {
|
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|e| {
|
||||||
eprintln!("{}: {}: Not an integer.", argv[0], argv[1]);
|
eprintln!("{}: {}: {}.", argv[0], argv[1], e);
|
||||||
exit(EX_DATAERR);
|
exit(EX_DATAERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ fn main() {
|
|||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap_or_else( |_| {
|
.unwrap_or_else( |e| {
|
||||||
eprintln!("{}: {}: Command not found.", argv[0], argv[command_arg]);
|
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||||
exit(EX_UNAVAILABLE);
|
exit(EX_UNAVAILABLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ fn main() {
|
|||||||
eprintln!(
|
eprintln!(
|
||||||
"{}: {}: No such index in input.",
|
"{}: {}: No such index in input.",
|
||||||
argv[0],
|
argv[0],
|
||||||
index.to_string()
|
index.to_string(),
|
||||||
);
|
);
|
||||||
exit(EX_DATAERR);
|
exit(EX_DATAERR);
|
||||||
});
|
});
|
||||||
@ -93,11 +93,8 @@ fn main() {
|
|||||||
drop(child_stdin);
|
drop(child_stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = spawned.wait_with_output().unwrap_or_else(|_| {
|
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
||||||
eprintln!("{}: {}: Command has no output.",
|
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||||
argv[0],
|
|
||||||
argv[command_arg]
|
|
||||||
);
|
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -105,16 +102,17 @@ fn main() {
|
|||||||
|
|
||||||
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
||||||
|
|
||||||
let new_field = String::from_utf8(replace).unwrap_or_else(|_| {
|
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
||||||
eprintln!(
|
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
|
||||||
"{}: {}: Command output is invalid UTF-8.",
|
|
||||||
argv[0],
|
|
||||||
argv[command_arg]
|
|
||||||
);
|
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
fields[index] = &new_field;
|
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