diff options
| author | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
| commit | 19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52 (patch) | |
| tree | 22353b8c7a78b83c992b7bfb60c024fee6f78e3e /crates/whirl_prompt/src | |
| parent | chore(rustfmt): add new rules (diff) | |
| download | whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.tar.xz whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.zip | |
format: rustfmt with new rules
Diffstat (limited to 'crates/whirl_prompt/src')
| -rw-r--r-- | crates/whirl_prompt/src/builtins/mod.rs | 52 | ||||
| -rw-r--r-- | crates/whirl_prompt/src/lib.rs | 61 | ||||
| -rw-r--r-- | crates/whirl_prompt/src/structure.rs | 4 |
3 files changed, 54 insertions, 63 deletions
diff --git a/crates/whirl_prompt/src/builtins/mod.rs b/crates/whirl_prompt/src/builtins/mod.rs index 047046b..b7f98b3 100644 --- a/crates/whirl_prompt/src/builtins/mod.rs +++ b/crates/whirl_prompt/src/builtins/mod.rs @@ -4,11 +4,15 @@ pub mod constants; pub mod structures; -use std::io::Write; - -use constants::{FILES, HELPABLES_BUILTINS, HELPABLES_BUILTIN_CONFIG, HELPABLES_BUILTIN_FETCH}; -use sysinfo::SystemExt; -use whirl_config::Config; +use { + constants::{ + FILES, HELPABLES_BUILTINS, HELPABLES_BUILTIN_CONFIG, + HELPABLES_BUILTIN_FETCH, + }, + std::io::Write, + sysinfo::SystemExt, + whirl_config::Config, +}; pub fn builtin_echo(args: &[String]) -> i32 { println!("{}", args.join(" ")); @@ -76,16 +80,15 @@ pub fn builtin_cat(args: &[String]) -> i32 { pub fn builtin_config(args: &[String]) -> i32 { match args.get(0) { - Some(sub) => - match sub.as_str() { - "show" => println!("{:#?}", Config::get()), - "help" | "--help" | "-h" => - for help in &HELPABLES_BUILTIN_CONFIG { - println!("{}", help); - }, - // "refresh" => Config::refresh(), - _ => println!("invalid arguments provided"), - }, + Some(sub) => match sub.as_str() { + "show" => println!("{:#?}", Config::get()), + "help" | "--help" | "-h" => + for help in &HELPABLES_BUILTIN_CONFIG { + println!("{}", help); + }, + // "refresh" => Config::refresh(), + _ => println!("invalid arguments provided"), + }, None => println!("invalid amount arguments provided"), } 0 @@ -100,17 +103,16 @@ pub fn builtin_fetch(args: &[String]) -> i32 { #[allow(clippy::single_match)] match args.get(0) { - Some(sub) => - match sub.as_str() { - "--whirl" | "-w" => whirl_image = true, - "help" | "--help" | "-h" => { - for help in &HELPABLES_BUILTIN_FETCH { - println!("{}", help); - } - return 0; + Some(sub) => match sub.as_str() { + "--whirl" | "-w" => whirl_image = true, + "help" | "--help" | "-h" => { + for help in &HELPABLES_BUILTIN_FETCH { + println!("{}", help); } - _ => println!("invalid arguments provided"), - }, + return 0; + } + _ => println!("invalid arguments provided"), + }, _ => (), } diff --git a/crates/whirl_prompt/src/lib.rs b/crates/whirl_prompt/src/lib.rs index 0c5c717..692282f 100644 --- a/crates/whirl_prompt/src/lib.rs +++ b/crates/whirl_prompt/src/lib.rs @@ -28,23 +28,16 @@ mod builtins; mod structure; -use std::{io, io::Write, str::FromStr}; - -use whirl_config::Config; - -use crate::{ - builtins::{ - builtin_cat, - builtin_clear, - builtin_config, - builtin_echo, - builtin_fetch, - builtin_help, - builtin_history, - builtin_ls, - structures::BuiltIn, +use { + crate::{ + builtins::{ + builtin_cat, builtin_clear, builtin_config, builtin_echo, builtin_fetch, + builtin_help, builtin_history, builtin_ls, structures::BuiltIn, + }, + structure::Command, }, - structure::Command, + std::{io, io::Write, str::FromStr}, + whirl_config::Config, }; pub struct Prompt { @@ -53,9 +46,7 @@ pub struct Prompt { impl Prompt { /// Begin handling user input as the prompt. pub async fn handle() -> ! { - let mut prompt = Self { - history: vec![] - }; + let mut prompt = Self { history: vec![] }; loop { Self::write_prompt(); @@ -83,15 +74,10 @@ impl Prompt { } fn tokenize_command(c: &str) -> Command { - let mut command_split: Vec<String> = c - .split_whitespace() - .map(std::string::ToString::to_string) - .collect(); - - Command { - keyword: command_split.remove(0), - args: command_split, - } + let mut command_split: Vec<String> = + c.split_whitespace().map(std::string::ToString::to_string).collect(); + + Command { keyword: command_split.remove(0), args: command_split } } // TODO: Find a way to make this access itself `history` doesn't have to be @@ -131,25 +117,26 @@ mod tokenize_command { fn empty_command() { assert_eq!("", Prompt::tokenize_command("").keyword) } #[test] - fn test_keyword() { assert_eq!("test", Prompt::tokenize_command("test").keyword) } + fn test_keyword() { + assert_eq!("test", Prompt::tokenize_command("test").keyword) + } #[test] fn no_arg() { assert_eq!(0, Prompt::tokenize_command("test").args.len()) } #[test] - fn one_arg() { assert_eq!(1, Prompt::tokenize_command("test one").args.len()) } + fn one_arg() { + assert_eq!(1, Prompt::tokenize_command("test one").args.len()) + } #[test] - fn multi_arg() { assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()) } + fn multi_arg() { + assert_eq!(3, Prompt::tokenize_command("test one two three").args.len()) + } #[test] #[ignore] fn quotes() { - assert_eq!( - 2, - Prompt::tokenize_command("test \"one two\" three") - .args - .len() - ) + assert_eq!(2, Prompt::tokenize_command("test \"one two\" three").args.len()) } } diff --git a/crates/whirl_prompt/src/structure.rs b/crates/whirl_prompt/src/structure.rs index 9914385..16eccc4 100644 --- a/crates/whirl_prompt/src/structure.rs +++ b/crates/whirl_prompt/src/structure.rs @@ -6,5 +6,7 @@ pub struct Command { pub args: Vec<String>, } impl Command { - pub fn to_line(&self) -> String { format!("{} {}", self.keyword, self.args.join(" ")) } + pub fn to_line(&self) -> String { + format!("{} {}", self.keyword, self.args.join(" ")) + } } |