From a1e8bb505c0c61bf3cf43a0923752a00aa921c9a Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Tue, 24 Jan 2023 13:10:04 +0100 Subject: [PATCH 01/15] fix: update mega to mebi bytes --- src/builtins/fetch.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/builtins/fetch.rs b/src/builtins/fetch.rs index 7ba16aa..434b31f 100644 --- a/src/builtins/fetch.rs +++ b/src/builtins/fetch.rs @@ -35,10 +35,10 @@ impl Builtin for Fetch { println!("{} {}", "UPTIME".red().bold(), format_uptime(sys.uptime())); println!("{} {}", "CPU".magenta().bold(), sys.cpus()[0].brand()); println!( - "{} {}MB / {}MB", + "{} {}MiB / {}MiB", "MEMORY".cyan().bold(), - bytes_to_mega_bytes(sys.used_memory()), - bytes_to_mega_bytes(sys.total_memory()) + bytes_to_mebi_bytes(sys.used_memory()), + bytes_to_mebi_bytes(sys.total_memory()) ); Ok(()) @@ -53,7 +53,7 @@ fn format_uptime(uptime: u64) -> String { format!("{:.0}h {:.0}m {:.0}s", h, m, s) } -fn bytes_to_mega_bytes(bytes: u64) -> u64 { +fn bytes_to_mebi_bytes(bytes: u64) -> u64 { bytes / 1024 / 1024 } From bdfa1a4a8ab7d6c57f0de052059d00a2dc01520b Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Tue, 24 Jan 2023 13:24:32 +0100 Subject: [PATCH 02/15] test: add bytes to mebi bytes test --- src/builtins/fetch.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/builtins/fetch.rs b/src/builtins/fetch.rs index 434b31f..f07ea29 100644 --- a/src/builtins/fetch.rs +++ b/src/builtins/fetch.rs @@ -75,4 +75,9 @@ mod tests { fn test_format_uptime_hours() { assert_eq!(format_uptime(3735), "1h 2m 15s"); } + + #[test] + fn test_bytes_to_mebi_bytes() { + assert_eq!(bytes_to_mebi_bytes(7628144640), 7274); + } } From 860b722933a0a4b62bca5b059446ce555b8b3fd2 Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Tue, 24 Jan 2023 14:46:42 +0100 Subject: [PATCH 03/15] refactoring: use let else instead of match --- src/builtins/ls.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 7822da6..55338f1 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -16,12 +16,9 @@ impl Builtin for Ls { //for entry in entries.by_ref().into_iter() {} for entry in entries { - let entry = match entry { - Ok(e) => e, - Err(_) => { - println!("Couldn't get directory entry"); - continue; - } + let Ok(entry) = entry else { + eprintln!("Couldn't get directory entry"); + continue; }; let file_name = entry.file_name().to_string_lossy().to_string(); let mut file_type = "unknown"; From ca6219e5263291c0e5cc68200aade638c448724a Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Tue, 24 Jan 2023 14:49:52 +0100 Subject: [PATCH 04/15] feat: add segfault command --- src/builtins/mod.rs | 2 ++ src/builtins/segfault.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/builtins/segfault.rs diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index b2d257a..f883519 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -9,6 +9,7 @@ mod fetch; mod ls; mod open; mod pwd; +mod segfault; pub struct BuiltinConfig { pub prompt_style: PromptStyle, @@ -35,6 +36,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("open", Box::new(open::Open)), ("fetch", Box::new(fetch::Fetch)), ("ls", Box::new(ls::Ls)), + ("segfault", Box::new(segfault::Segfault)), ] }); diff --git a/src/builtins/segfault.rs b/src/builtins/segfault.rs new file mode 100644 index 0000000..396d234 --- /dev/null +++ b/src/builtins/segfault.rs @@ -0,0 +1,11 @@ +use crate::builtins::{Builtin, BuiltinConfig}; +use crate::error::ShellError; + +pub struct Segfault; + +impl Builtin for Segfault { + fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { + unsafe { std::ptr::null_mut::().write(69) }; + Ok(()) + } +} From 50066f536c49fc86983bf1db4764c0edc76257b1 Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Tue, 24 Jan 2023 14:51:02 +0100 Subject: [PATCH 05/15] refactoring: sort builtins --- src/builtins/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index f883519..5bfd00c 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -32,10 +32,10 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("cd", Box::new(cd::Cd)), ("change-prompt", Box::new(change_prompt::ChangePrompt)), ("exit", Box::new(exit::Exit)), - ("pwd", Box::new(pwd::Pwd)), - ("open", Box::new(open::Open)), ("fetch", Box::new(fetch::Fetch)), ("ls", Box::new(ls::Ls)), + ("open", Box::new(open::Open)), + ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), ] }); From 719705616636ada213638f0d4bc038c03a8fe94c Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Wed, 25 Jan 2023 13:34:00 +0100 Subject: [PATCH 06/15] feat: add filename completion --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/main.rs | 21 +++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 766acb9..dc95538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -375,6 +375,7 @@ dependencies = [ "once_cell", "regex", "rustyline", + "rustyline-derive", "shlex", "sysinfo", "uname", @@ -505,6 +506,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustyline-derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "107c3d5d7f370ac09efa62a78375f94d94b8a33c61d8c278b96683fb4dbf2d8d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "scopeguard" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1333d8e..1aa8263 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ dirs = "4.0" once_cell = "1.17" regex = "1.7" rustyline = "10.1" +rustyline-derive = "0.7" shlex = "1.1" sysinfo = "0.27" uname = "0.1" diff --git a/src/main.rs b/src/main.rs index f7ad6e4..e79b195 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,11 @@ use crate::builtins::BuiltinConfig; use crate::prompt::Prompt; use colored::Colorize; use execute::interpret; +use rustyline::completion::FilenameCompleter; use rustyline::config::Configurer; use rustyline::error::ReadlineError; -use rustyline::{Editor, Result}; +use rustyline::{CompletionType, Config, Editor, Result}; +use rustyline_derive::{Completer, Helper, Highlighter, Hinter, Validator}; use whoami::username; mod builtins; @@ -14,13 +16,28 @@ mod parse; mod preprocess; mod prompt; +#[derive(Completer, Helper, Highlighter, Hinter, Validator)] +struct EditorHelper { + #[rustyline(Completer)] + completer: FilenameCompleter, +} + fn main() -> Result<()> { let (ctrlc_send, ctrlc_recv) = crossbeam_channel::unbounded::<()>(); let _ = ctrlc::set_handler(move || { let _ = ctrlc_send.send(()); }); - let mut rl = Editor::<()>::new()?; + let config = Config::builder() + .completion_type(CompletionType::List) + .build(); + + let helper = EditorHelper { + completer: FilenameCompleter::new(), + }; + + let mut rl = Editor::with_config(config)?; + rl.set_helper(Some(helper)); rl.set_auto_add_history(true); let mut prompt = Prompt::new(); From 7d3e8f741ef2cd45b85016fc53b61075596acd81 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Wed, 25 Jan 2023 23:34:21 +0100 Subject: [PATCH 07/15] feat: add sus command --- src/builtins/mod.rs | 2 ++ src/builtins/sus.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/builtins/sus.rs diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 5bfd00c..5853b11 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -10,6 +10,7 @@ mod ls; mod open; mod pwd; mod segfault; +mod sus; pub struct BuiltinConfig { pub prompt_style: PromptStyle, @@ -37,6 +38,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("open", Box::new(open::Open)), ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), + ("sus",Box::new(sus::sus)), ] }); diff --git a/src/builtins/sus.rs b/src/builtins/sus.rs new file mode 100644 index 0000000..3a34089 --- /dev/null +++ b/src/builtins/sus.rs @@ -0,0 +1,30 @@ +use crate::error::ShellError; +use crate::builtins::{Builtin, BuiltinConfig}; + + +pub struct sus; + +impl Builtin for sus { + fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { + println!(" + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⡀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀⣠⣶⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣄⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⢰⣿⣿⣯⠁⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣷⡄⠀ + ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⠀⢸⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⠀ + ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀⠀⠀⠘⣿⣿⣿⣿⣷⣦⣤⣤⣤⣶⣶⣶⣶⣿⣿⣿⠀ + ⠀⢸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀ + ⠀⣸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠉⠻⠿⣿⣿⣿⣿⡿⠿⠿⠛⢻⣿⡇⠀⠀ + ⠀⣿⣿⠁⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣧⠀⠀ + ⠀⢿⣿⡆⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡇⠀⠀ + ⠀⠸⣿⣧⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠃⠀⠀ + ⠀⠀⠛⢿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⣰⣿⣿⣷⣶⣶⣶⣶⠶⠀⢠⣿⣿⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡏⠁⠀⠀⢸⣿⡇⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"); + Ok(()) + } +} \ No newline at end of file From 9d409c0f2cf7f0e73f7e86ee9ce9bb08b92c899d Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Wed, 25 Jan 2023 23:38:51 +0100 Subject: [PATCH 08/15] refactoring: sus struct to upper camel case --- src/builtins/mod.rs | 2 +- src/builtins/sus.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 5853b11..19cb5e3 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -38,7 +38,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("open", Box::new(open::Open)), ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), - ("sus",Box::new(sus::sus)), + ("sus",Box::new(sus::Sus)), ] }); diff --git a/src/builtins/sus.rs b/src/builtins/sus.rs index 3a34089..a84616c 100644 --- a/src/builtins/sus.rs +++ b/src/builtins/sus.rs @@ -2,9 +2,9 @@ use crate::error::ShellError; use crate::builtins::{Builtin, BuiltinConfig}; -pub struct sus; +pub struct Sus; -impl Builtin for sus { +impl Builtin for Sus { fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { println!(" ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ From 2d24febc2b9665a3bf057ef110fd79d236563e7a Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Wed, 25 Jan 2023 23:43:54 +0100 Subject: [PATCH 09/15] refactoring: sort imports, aligned bracket --- src/builtins/sus.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/builtins/sus.rs b/src/builtins/sus.rs index a84616c..8eaebe7 100644 --- a/src/builtins/sus.rs +++ b/src/builtins/sus.rs @@ -1,6 +1,5 @@ -use crate::error::ShellError; use crate::builtins::{Builtin, BuiltinConfig}; - +use crate::error::ShellError; pub struct Sus; @@ -24,7 +23,7 @@ impl Builtin for Sus { ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -"); + "); Ok(()) } } \ No newline at end of file From 31fa8007364fdfd2ce54f9e0080260c1242aa2e2 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Thu, 26 Jan 2023 00:09:04 +0100 Subject: [PATCH 10/15] chore: deactivate ci --- .gitlab-ci.yml => ._gitlab-ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .gitlab-ci.yml => ._gitlab-ci.yml (100%) diff --git a/.gitlab-ci.yml b/._gitlab-ci.yml similarity index 100% rename from .gitlab-ci.yml rename to ._gitlab-ci.yml From 6aea187395bc3c573b380bdb577050eacb7a2758 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Thu, 26 Jan 2023 00:30:11 +0100 Subject: [PATCH 11/15] refactoring: format sus command --- src/builtins/mod.rs | 2 +- src/builtins/sus.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 19cb5e3..7b24b29 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -38,7 +38,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("open", Box::new(open::Open)), ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), - ("sus",Box::new(sus::Sus)), + ("sus", Box::new(sus::Sus)), ] }); diff --git a/src/builtins/sus.rs b/src/builtins/sus.rs index 8eaebe7..cb01dcb 100644 --- a/src/builtins/sus.rs +++ b/src/builtins/sus.rs @@ -5,7 +5,8 @@ pub struct Sus; impl Builtin for Sus { fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { - println!(" + println!( + " ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⡀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀ @@ -23,7 +24,8 @@ impl Builtin for Sus { ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - "); + " + ); Ok(()) } -} \ No newline at end of file +} From 2c74829438dd3f940b02546f44383ef901a1b4d6 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Thu, 26 Jan 2023 20:47:00 +0100 Subject: [PATCH 12/15] test: add sus is builtin command test --- src/builtins/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 7b24b29..96913eb 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -95,6 +95,11 @@ mod tests { assert_eq!(is_builtin("change-prompt"), true); } + #[test] + fn test_is_builtin_sus() { + assert_eq!(is_builtin("sus"), true); + } + #[test] fn test_is_builtin_notabuiltin() { assert_eq!(is_builtin("notabuiltin"), false) From 83dad1f4d692a5e1970d0df1ba688682f8bd2547 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Sat, 28 Jan 2023 18:50:34 +0100 Subject: [PATCH 13/15] feat: add help command --- src/builtins/help.rs | 27 +++++++++++++++++++++++++++ src/builtins/mod.rs | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 src/builtins/help.rs diff --git a/src/builtins/help.rs b/src/builtins/help.rs new file mode 100644 index 0000000..d78b5d5 --- /dev/null +++ b/src/builtins/help.rs @@ -0,0 +1,27 @@ +use crate::error::ShellError; +use crate::builtins::{Builtin, BuiltinConfig}; + + +pub struct Help; + +impl Builtin for Help { + + fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { + let commands = + "cd changes current working directory + change-prompt changes prompt style (default, bashlike, simpledirectory) + exit exits the shell + fetch prints out system information + help displays this command + ls lists contents of directory + open shows content of files + pwd shows path to current working directory + segfault exit but through segfault + sus shows amogus"; + + for line in commands.lines(){ + println!("{}",line.trim_start()); + } + Ok(()) + } +} \ No newline at end of file diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 96913eb..51ccbe6 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -6,6 +6,7 @@ mod cd; mod change_prompt; mod exit; mod fetch; +mod help; mod ls; mod open; mod pwd; @@ -39,6 +40,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), ("sus", Box::new(sus::Sus)), + ("help", Box::new(help::Help)), ] }); From 4d1e264e8c2cbff570ca7ff3be14e012c90391c4 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Sat, 28 Jan 2023 19:08:27 +0100 Subject: [PATCH 14/15] refactoring: format help command --- src/builtins/help.rs | 8 +++----- src/builtins/mod.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/builtins/help.rs b/src/builtins/help.rs index d78b5d5..4fbe17e 100644 --- a/src/builtins/help.rs +++ b/src/builtins/help.rs @@ -1,11 +1,9 @@ -use crate::error::ShellError; use crate::builtins::{Builtin, BuiltinConfig}; - +use crate::error::ShellError; pub struct Help; impl Builtin for Help { - fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { let commands = "cd changes current working directory @@ -19,8 +17,8 @@ impl Builtin for Help { segfault exit but through segfault sus shows amogus"; - for line in commands.lines(){ - println!("{}",line.trim_start()); + for line in commands.lines() { + println!("{}", line.trim_start()); } Ok(()) } diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 51ccbe6..2da1a20 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -35,12 +35,12 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("change-prompt", Box::new(change_prompt::ChangePrompt)), ("exit", Box::new(exit::Exit)), ("fetch", Box::new(fetch::Fetch)), + ("help", Box::new(help::Help)), ("ls", Box::new(ls::Ls)), ("open", Box::new(open::Open)), ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), ("sus", Box::new(sus::Sus)), - ("help", Box::new(help::Help)), ] }); From d9903c8db43ef54d7e0a72c529d58584520a96db Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Sat, 28 Jan 2023 19:23:55 +0100 Subject: [PATCH 15/15] test: add help is builtin command test --- src/builtins/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 2da1a20..22470e4 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -82,6 +82,11 @@ mod tests { assert_eq!(is_builtin("pwd"), true); } + #[test] + fn test_is_builtin_help() { + assert_eq!(is_builtin("help"), true); + } + #[test] fn test_is_builtin_ls() { assert_eq!(is_builtin("ls"), true);