diff --git a/Cargo.lock b/Cargo.lock index b94297c..3190b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,9 +211,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.29" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e804ac3194a48bb129643eb1d62fcc20d18c6b8c181704489353d13120bcd1" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ "jobserver", "libc", @@ -694,7 +694,6 @@ dependencies = [ "rustyline", "rustyline-derive", "shlex", - "walkdir", "whoami", ] diff --git a/i6-shell/Cargo.toml b/i6-shell/Cargo.toml index 97df7ee..9934543 100644 --- a/i6-shell/Cargo.toml +++ b/i6-shell/Cargo.toml @@ -14,7 +14,6 @@ categories = ["command-line-interface", "command-line-utilities", "development-t workspace = true [dependencies] -walkdir = "2" rustyline = "14" rustyline-derive = "0.10" chrono = "0.4" diff --git a/i6-shell/src/command.rs b/i6-shell/src/command.rs index 77e4c7f..0e644c1 100644 --- a/i6-shell/src/command.rs +++ b/i6-shell/src/command.rs @@ -1,3 +1,6 @@ +#![allow(non_camel_case_types)] +#![allow(unused_variables)] + use std::{ collections::HashMap, sync::{Arc, Mutex}, @@ -35,7 +38,7 @@ impl Command for cd { let args = input.split(" ").collect::>(); let deafult_path = &""; - let mut path = args.get(0).unwrap_or(deafult_path).to_string(); + let mut path = args.first().unwrap_or(deafult_path).to_string(); let _ = COMMAND_STATE.lock().map(|mut lock| { if (path == "-") { @@ -73,11 +76,11 @@ impl Command for ls { let used_args = vec!["-la"]; let mut path = "."; - args.last().map(|x| { - if (is_path(x, used_args)) { + if let Some(x) = args.last() { + if is_path(x, used_args) { path = x; } - }); + } let mut items = std::fs::read_dir(path) .map_err(|e| Box::new(e) as Box)? @@ -91,7 +94,7 @@ impl Command for ls { if (list_all) { for i in 0..items.len() { - let metadata = std::fs::metadata(&path) + let metadata = std::fs::metadata(path) .map_err(|e| Box::new(e) as Box)?; let file_type = metadata.file_type(); let permissions = metadata.permissions(); @@ -141,7 +144,12 @@ impl Command for touch { input: &str, ) -> Result> { let path = std::path::Path::new(input); - match std::fs::OpenOptions::new().create(true).write(true).open(&path) { + match std::fs::OpenOptions::new() + .create(true) + .truncate(false) + .write(true) + .open(path) + { Ok(file) => { let now = std::time::SystemTime::now(); file @@ -162,7 +170,7 @@ impl Command for mkdir { input: &str, ) -> Result> { let path = std::path::Path::new(input); - std::fs::create_dir_all(&path) + std::fs::create_dir_all(path) .map_err(|e| Box::new(e) as Box)?; Ok("".into()) } @@ -452,15 +460,12 @@ impl Command for grep { } } +type CommandResult = + Result>, Box>; +type CommandMap = Arc>; + lazy_static! { - pub static ref DEFAULT_COMMANDS: Arc< - Mutex< - Result< - HashMap>, - Box, - >, - >, - > = Arc::new(Mutex::new({ + pub static ref DEFAULT_COMMANDS: CommandMap = Arc::new(Mutex::new({ let mut result: HashMap> = Default::default(); result.insert("cd".to_owned(), Box::new(cd)); diff --git a/i6-shell/src/lang.rs b/i6-shell/src/lang.rs index a51b340..df01852 100644 --- a/i6-shell/src/lang.rs +++ b/i6-shell/src/lang.rs @@ -132,10 +132,8 @@ impl Parser for DefaultParser { if token.value == "|" { let right = args.pop().unwrap(); let left = args.pop().unwrap(); - root = ASTNode::Pipe { - left: Box::new(left), - right: Box::new(right), - }; + root = + ASTNode::Pipe { left: Box::new(left), right: Box::new(right) }; } else { root = ASTNode::Operator { op: token.value, args }; } @@ -218,16 +216,15 @@ impl Interpreter for DefaultInterpreter { } } - match name.as_str() { - command => { - let child = std::process::Command::new(command).args(args).spawn(); + let command = name.as_str(); + { + let child = std::process::Command::new(command).args(args).spawn(); - match child { - Ok(mut child) => { - child.wait().unwrap(); - } - Err(e) => eprintln!("{}", e), + match child { + Ok(mut child) => { + child.wait().unwrap(); } + Err(e) => eprintln!("{}", e), } } } @@ -288,8 +285,8 @@ impl Interpreter for DefaultInterpreter { }; let output = second_command - .wait_with_output() - .expect("Failed to wait on second command"); + .wait_with_output() + .expect("Failed to wait on second command"); println!("{}", String::from_utf8_lossy(&output.stdout)); } diff --git a/i6-shell/src/lib.rs b/i6-shell/src/lib.rs index 2c434ba..6dd8dcf 100644 --- a/i6-shell/src/lib.rs +++ b/i6-shell/src/lib.rs @@ -1,3 +1,6 @@ +#![allow(non_camel_case_types)] +#![allow(unused_variables)] + use std::borrow::Cow::{self, Borrowed, Owned}; use std::collections::HashMap; diff --git a/i6/src/main.rs b/i6/src/main.rs index 723c83f..9cc0cd1 100644 --- a/i6/src/main.rs +++ b/i6/src/main.rs @@ -1,6 +1,6 @@ use clap::{value_parser, Arg, Command}; -use std::error::Error; use i6_shell::lang::DefaultInterpreter; +use std::error::Error; #[tokio::main] async fn main() -> Result<(), Box> { @@ -30,9 +30,7 @@ async fn main() -> Result<(), Box> { .value_parser(value_parser!(u16)), ), ) - .subcommand( - Command::new(sh_id).about("Start an interactive shell") - ) + .subcommand(Command::new(sh_id).about("Start an interactive shell")) .subcommand( Command::new("timer") .about("Manages timers")