tentative argument parsing
This commit is contained in:
parent
b3da4df9ec
commit
9c0e14ba35
@ -8,16 +8,30 @@ use std::process;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().skip(1).collect();
|
let args: Vec<String> = env::args().skip(1).collect();
|
||||||
|
let mut opts = Vec::new();
|
||||||
|
|
||||||
for i in args {
|
for arg in &args {
|
||||||
let mut arg = i.as_str();
|
if arg.starts_with("-") {
|
||||||
match arg {
|
opts.push(arg);
|
||||||
"-u" => process::exit(1),
|
}
|
||||||
|
|
||||||
_ => {
|
|
||||||
print!("{}", read_to_string(arg).unwrap())
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.is_empty() == false {
|
||||||
|
for option in opts {
|
||||||
|
match option.as_str() {
|
||||||
|
// Write bytes from the input file to the standard output without
|
||||||
|
// delay as each is read.
|
||||||
|
"-u" => {},
|
||||||
|
|
||||||
|
_ => process::exit(1),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for path in args {
|
||||||
|
print!("{}", read_to_string(path).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user