aboutsummaryrefslogtreecommitdiff
path: root/crates/whirl_prompt/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-28 00:06:40 -0700
committerFuwn <[email protected]>2021-05-28 00:06:40 -0700
commit179ce3277ece536cae41b834469f4065e3600d82 (patch)
treea96d55a34531c9761f6309c35f8d9cfab9879db6 /crates/whirl_prompt/src
parentMerge branch 'develop' of https://github.com/Whirlsplash/whirl into develop (diff)
downloadwhirl-179ce3277ece536cae41b834469f4065e3600d82.tar.xz
whirl-179ce3277ece536cae41b834469f4065e3600d82.zip
fix(global): a lot of clippy warnings
This change makes clippy **a lot** more strict.
Diffstat (limited to 'crates/whirl_prompt/src')
-rw-r--r--crates/whirl_prompt/src/builtins/mod.rs4
-rw-r--r--crates/whirl_prompt/src/builtins/structures.rs18
-rw-r--r--crates/whirl_prompt/src/lib.rs51
3 files changed, 36 insertions, 37 deletions
diff --git a/crates/whirl_prompt/src/builtins/mod.rs b/crates/whirl_prompt/src/builtins/mod.rs
index 62031de..2bebd31 100644
--- a/crates/whirl_prompt/src/builtins/mod.rs
+++ b/crates/whirl_prompt/src/builtins/mod.rs
@@ -23,7 +23,7 @@ pub fn builtin_history(history: &[String]) -> i32 {
}
pub fn builtin_help() -> i32 {
- for help in HELPABLES_BUILTINS.iter() {
+ for help in &HELPABLES_BUILTINS {
println!("{}", help);
}
@@ -80,7 +80,7 @@ pub fn builtin_config(args: &[String]) -> i32 {
match sub.as_str() {
"show" => println!("{:#?}", Config::get()),
"help" | "--help" | "-h" =>
- for help in HELPABLES_BUILTIN_CONFIG.iter() {
+ for help in &HELPABLES_BUILTIN_CONFIG {
println!("{}", help);
},
// "refresh" => Config::refresh(),
diff --git a/crates/whirl_prompt/src/builtins/structures.rs b/crates/whirl_prompt/src/builtins/structures.rs
index 4217a38..59df31b 100644
--- a/crates/whirl_prompt/src/builtins/structures.rs
+++ b/crates/whirl_prompt/src/builtins/structures.rs
@@ -19,15 +19,15 @@ impl FromStr for BuiltIn {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
- "echo" => Ok(BuiltIn::Echo),
- "history" => Ok(BuiltIn::History),
- "exit" => Ok(BuiltIn::Exit),
- "null" => Ok(BuiltIn::Null),
- "help" => Ok(BuiltIn::Help),
- "ls" => Ok(BuiltIn::Ls),
- "cat" => Ok(BuiltIn::Cat),
- "config" => Ok(BuiltIn::Config),
- "fetch" => Ok(BuiltIn::Fetch),
+ "echo" => Ok(Self::Echo),
+ "history" => Ok(Self::History),
+ "exit" => Ok(Self::Exit),
+ "null" => Ok(Self::Null),
+ "help" => Ok(Self::Help),
+ "ls" => Ok(Self::Ls),
+ "cat" => Ok(Self::Cat),
+ "config" => Ok(Self::Config),
+ "fetch" => Ok(Self::Fetch),
_ => Err(()),
}
}
diff --git a/crates/whirl_prompt/src/lib.rs b/crates/whirl_prompt/src/lib.rs
index e33adce..a7b2389 100644
--- a/crates/whirl_prompt/src/lib.rs
+++ b/crates/whirl_prompt/src/lib.rs
@@ -10,7 +10,15 @@
decl_macro,
proc_macro_hygiene
)]
-#![warn(rust_2018_idioms)]
+#![deny(
+ warnings,
+ nonstandard_style,
+ unused,
+ future_incompatible,
+ rust_2018_idioms,
+ unsafe_code
+)]
+#![deny(clippy::all, clippy::nursery, clippy::pedantic)]
#![recursion_limit = "128"]
mod builtins;
@@ -40,15 +48,15 @@ pub struct Prompt {
impl Prompt {
/// Begin handling user input as the prompt.
pub async fn handle() -> ! {
- let mut prompt = Prompt {
+ let mut prompt = Self {
history: vec![]
};
loop {
- Prompt::write_prompt();
- let command = prompt.read_command();
+ Self::write_prompt();
+ let command = Self::read_command();
prompt
- .process_command(Prompt::tokenize_command(command))
+ .process_command(Self::tokenize_command(&command))
.await;
}
}
@@ -58,7 +66,7 @@ impl Prompt {
io::stdout().flush().unwrap();
}
- fn read_command(&mut self) -> String {
+ fn read_command() -> String {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
@@ -71,8 +79,11 @@ impl Prompt {
input
}
- fn tokenize_command(c: String) -> Command {
- let mut command_split: Vec<String> = c.split_whitespace().map(|s| s.to_string()).collect();
+ 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),
@@ -113,38 +124,26 @@ mod tokenize_command {
#[test]
#[ignore]
- fn empty_command() { assert_eq!("", Prompt::tokenize_command("".to_string()).keyword) }
+ fn empty_command() { assert_eq!("", Prompt::tokenize_command("").keyword) }
#[test]
- fn test_keyword() { assert_eq!("test", Prompt::tokenize_command("test".to_string()).keyword) }
+ fn test_keyword() { assert_eq!("test", Prompt::tokenize_command("test").keyword) }
#[test]
- fn no_arg() { assert_eq!(0, Prompt::tokenize_command("test".to_string()).args.len()) }
+ fn no_arg() { assert_eq!(0, Prompt::tokenize_command("test").args.len()) }
#[test]
- fn one_arg() {
- assert_eq!(
- 1,
- Prompt::tokenize_command("test one".to_string()).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".to_string())
- .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".to_string())
+ Prompt::tokenize_command("test \"one two\" three")
.args
.len()
)