Rust noob here, you might remember me from past threads.
The thing is I'm not only a Rust noob but my programming logic is quite bad, also.
I am trying to write a cat clone but I'm confused about how to aproach it. Right now I have the basic functionality working but I would like to implement giving the program no arguments, and giving it the -n option.
For the -n option I am thinking about parsing each cmd line argument and if the argument contains an "-n", add the setting to print lines to the 'config' struct, which looks like the following:
pub struct Config {
pub files: Vec<String>,
}
impl Config {
pub fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 2 {
return Err("Not enough arguments");
}
let mut result = vec![];
let args = &args[1..];
for arg in args {
result.push(arg.clone());
}
let files = result;
Ok(Config { files })
}
}
For when the program is ran without arguments, should I just have it wait and read each line and then print it again? Is it that simple?