From 5d07a51aa4f5e03273d8198c5b17601fefe9ff87 Mon Sep 17 00:00:00 2001 From: fdai7375 Date: Mon, 30 Jan 2023 09:48:08 +0100 Subject: [PATCH] feat: add quote command --- Cargo.lock | 37 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/builtins/mod.rs | 2 ++ src/builtins/quote.rs | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/builtins/quote.rs diff --git a/Cargo.lock b/Cargo.lock index dc95538..424346b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -373,6 +373,7 @@ dependencies = [ "ctrlc", "dirs", "once_cell", + "rand", "regex", "rustyline", "rustyline-derive", @@ -382,6 +383,12 @@ dependencies = [ "whoami", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.49" @@ -410,6 +417,36 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rayon" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index 1aa8263..661e806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ shlex = "1.1" sysinfo = "0.27" uname = "0.1" whoami = "1.3" +rand = "0.8.5" diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 22470e4..aadf0f6 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -10,6 +10,7 @@ mod help; mod ls; mod open; mod pwd; +mod quote; mod segfault; mod sus; @@ -41,6 +42,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("pwd", Box::new(pwd::Pwd)), ("segfault", Box::new(segfault::Segfault)), ("sus", Box::new(sus::Sus)), + ("quote", Box::new(quote::Quote)), ] }); diff --git a/src/builtins/quote.rs b/src/builtins/quote.rs new file mode 100644 index 0000000..5e844c5 --- /dev/null +++ b/src/builtins/quote.rs @@ -0,0 +1,17 @@ +use rand::Rng; + +use crate::builtins::{Builtin, BuiltinConfig}; +use crate::error::ShellError; + +pub struct Quote; + +const QUOTES: &[(&str, &str)] = &[("test quote", "david")]; + +impl Builtin for Quote { + fn execute(&mut self, _: &mut BuiltinConfig, _: Vec) -> Result<(), ShellError> { + let mut rng = rand::thread_rng(); + let quote = QUOTES[rng.gen_range(0..QUOTES.len())]; + println!("{}\n - {}", quote.0, quote.1); + Ok(()) + } +}