Archived
2
0

proper error handling

This commit is contained in:
Emma Tebibyte 2022-12-05 19:04:28 -05:00
parent 9c0e14ba35
commit 1817f9b4ea

View File

@ -2,12 +2,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
use std::fs::read_to_string; use std::fs::read_to_string;
use std::io::{stdout, Write}; use std::io::{stdin, stdout, Write};
use std::env; use std::env;
use std::process; use std::process;
fn main() { fn main() {
let args: Vec<String> = env::args().skip(1).collect(); let mut args: Vec<String> = env::args().collect();
let argv0 = args.remove(0);
let mut opts = Vec::new(); let mut opts = Vec::new();
for arg in &args { for arg in &args {
@ -23,13 +24,22 @@ fn main() {
// delay as each is read. // delay as each is read.
"-u" => {}, "-u" => {},
_ => process::exit(1), _ => {
println! ("Usage: {} [options...] [files...]", argv0);
process::exit(64); // sysexits(3) EX_USAGE
},
}; };
} }
} }
else { else {
for path in args { for path in args {
print!("{}", read_to_string(path).unwrap()); match read_to_string(&path) {
Ok(val) => println!("{}", val),
Err(_) => {
println!("{}: {}: No such file or directory.", argv0, path);
process::exit(66); // sysexits(3) EX_NOINPUT
},
};
} }
} }