From 9c0e14ba35646764b353742199eaa6d51bedb41d Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 5 Dec 2022 00:48:19 -0500 Subject: [PATCH] tentative argument parsing --- src/bin/cat.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/bin/cat.rs b/src/bin/cat.rs index 364ae04..afe7f8f 100644 --- a/src/bin/cat.rs +++ b/src/bin/cat.rs @@ -8,16 +8,30 @@ use std::process; fn main() { let args: Vec = env::args().skip(1).collect(); - - for i in args { - let mut arg = i.as_str(); - match arg { - "-u" => process::exit(1), - - _ => { - print!("{}", read_to_string(arg).unwrap()) - }, - }; + let mut opts = Vec::new(); + + for arg in &args { + if arg.starts_with("-") { + opts.push(arg); + } } + + 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(); }