Remove cat builtin

This commit is contained in:
pjht 2024-11-24 07:39:48 -06:00
parent 9002fa3b35
commit e6838b3837
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -4,11 +4,6 @@ use std::{
use clap::Parser;
#[derive(Parser, Debug)]
struct Cat {
path: PathBuf,
}
#[derive(Parser, Debug)]
struct Cd {
path: PathBuf,
@ -42,28 +37,6 @@ fn main() {
};
match cmd[0].as_str() {
"pwd" => println!("{}", current_dir().unwrap().to_string_lossy()),
"cat" => {
let cmd = match Cat::try_parse_from(&cmd) {
Ok(cmd) => cmd,
Err(err) => {
err.print().unwrap();
continue;
}
};
let contents = match std::fs::read(&cmd.path) {
Ok(val) => val,
Err(e) => {
println!("cat: {}: {}", cmd.path.display(), e);
continue;
}
};
io::stdout().lock().write_all(&contents).unwrap();
if let Some(&last_byte) = contents.last() {
if last_byte != b'\n' {
println!("%");
}
}
}
"cd" => {
let cmd = match Cd::try_parse_from(&cmd) {
Ok(cmd) => cmd,
@ -86,7 +59,6 @@ fn main() {
"help" => {
println!("Commands:");
println!("pwd");
println!("cat");
println!("cd");
println!("exit");
println!("help");