Browse Source

feat: add quote command

main
fdai7375 2 years ago
committed by fdai7451
parent
commit
5d07a51aa4
  1. 37
      Cargo.lock
  2. 1
      Cargo.toml
  3. 2
      src/builtins/mod.rs
  4. 17
      src/builtins/quote.rs

37
Cargo.lock

@ -373,6 +373,7 @@ dependencies = [
"ctrlc", "ctrlc",
"dirs", "dirs",
"once_cell", "once_cell",
"rand",
"regex", "regex",
"rustyline", "rustyline",
"rustyline-derive", "rustyline-derive",
@ -382,6 +383,12 @@ dependencies = [
"whoami", "whoami",
] ]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.49" version = "1.0.49"
@ -410,6 +417,36 @@ dependencies = [
"nibble_vec", "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]] [[package]]
name = "rayon" name = "rayon"
version = "1.6.1" version = "1.6.1"

1
Cargo.toml

@ -16,3 +16,4 @@ shlex = "1.1"
sysinfo = "0.27" sysinfo = "0.27"
uname = "0.1" uname = "0.1"
whoami = "1.3" whoami = "1.3"
rand = "0.8.5"

2
src/builtins/mod.rs

@ -10,6 +10,7 @@ mod help;
mod ls; mod ls;
mod open; mod open;
mod pwd; mod pwd;
mod quote;
mod segfault; mod segfault;
mod sus; mod sus;
@ -41,6 +42,7 @@ const BUILTINS: Lazy<Vec<(&str, Box<dyn Builtin>)>> = Lazy::new(|| {
("pwd", Box::new(pwd::Pwd)), ("pwd", Box::new(pwd::Pwd)),
("segfault", Box::new(segfault::Segfault)), ("segfault", Box::new(segfault::Segfault)),
("sus", Box::new(sus::Sus)), ("sus", Box::new(sus::Sus)),
("quote", Box::new(quote::Quote)),
] ]
}); });

17
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<String>) -> Result<(), ShellError> {
let mut rng = rand::thread_rng();
let quote = QUOTES[rng.gen_range(0..QUOTES.len())];
println!("{}\n - {}", quote.0, quote.1);
Ok(())
}
}
Loading…
Cancel
Save