Ajout : lecture des commandes depuis stdin

This commit is contained in:
Hippolyte Chauvin 2023-10-28 15:17:51 +02:00
parent 544ca5076a
commit 675a176b77

View file

@ -1,18 +1,21 @@
use std::io;
mod parser;
fn main() {
let commands: Vec<&str> = vec![
"ls -l",
" amogus",
"lol ",
" fozafoazngin",
"amogus ",
"je suis fade up la",
" la c'est le bos final ",
];
let mut buffer = String::new();
let mut result_bytes_read: io::Result<usize> = Ok(1);
let commands_iter = commands.iter();
for command in commands_iter {
println!("{:?}", parser::parse(&String::from(*command)));
while result_bytes_read.unwrap() != 0 {
buffer.clear();
result_bytes_read = io::stdin().read_line(&mut buffer);
if !result_bytes_read.is_err() {
let command_vec: Vec<String> = parser::parse(&buffer);
println!("{:?}", command_vec);
} else {
eprintln!("error: invalid UTF-8 characters were read");
result_bytes_read = Ok(1);
}
}
}