aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-16 17:14:50 +0000
committerFuwn <[email protected]>2021-05-16 17:14:50 +0000
commit8bb76b285937b602df055dd241fd86d2be966380 (patch)
tree3e6dd57397e4280be2b1c163697b59632052fa5b /src
parentrefactor(builtins): help from individual printlns to vec iterable println (diff)
downloadwhirl-8bb76b285937b602df055dd241fd86d2be966380.tar.xz
whirl-8bb76b285937b602df055dd241fd86d2be966380.zip
perf(builtins): help commands to constants
This commit also reorders all helpables by alpabetical order.
Diffstat (limited to 'src')
-rw-r--r--src/prompt/builtins.rs39
-rw-r--r--src/utils/mod.rs1
-rw-r--r--src/utils/sort.rs6
3 files changed, 26 insertions, 20 deletions
diff --git a/src/prompt/builtins.rs b/src/prompt/builtins.rs
index ac22702..e8952bf 100644
--- a/src/prompt/builtins.rs
+++ b/src/prompt/builtins.rs
@@ -8,6 +8,21 @@ use sysinfo::SystemExt;
use crate::config::Config;
const FILES: [&str; 2] = ["README.rst", "Whirl.toml"];
+const HELPABLES_BUILTINS: [&str; 8] = [
+ "cat - display the contents of a present file",
+ "config - manipulate the configuration",
+ "echo - display a line of predefined text",
+ "exit - end the process",
+ "fetch - a neofetch like utility loosely based on rfetch",
+ "help - you are here",
+ "history - display the command history",
+ "ls - display the present files",
+];
+const HELPABLES_BUILTIN_CONFIG: [&str; 3] = [
+ "help - you are here",
+ "refresh - reload the configuration file",
+ "show - display the current configuration",
+];
pub enum BuiltIn {
Echo,
@@ -52,17 +67,7 @@ pub fn builtin_history(history: Vec<String>) -> i32 {
}
pub fn builtin_help() -> i32 {
- let helpables = vec![
- "echo - display a line of predefined text",
- "history - display the command history",
- "exit - end the process",
- "ls - display the present files",
- "cat - display the contents of a present file",
- "config - manipulate the configuration",
- "help - you are here",
- "fetch - a neofetch like utility loosely based on rfetch",
- ];
- for help in helpables {
+ for help in HELPABLES_BUILTINS.iter() {
println!("{}", help);
}
@@ -118,16 +123,10 @@ pub fn builtin_config(args: &[String]) -> i32 {
Some(sub) =>
match sub.as_str() {
"show" => println!("{:#?}", Config::get()),
- "help" | "--help" | "-h" => {
- let helpables = vec![
- "show - display the current configuration",
- "help - you are here",
- "refresh - reload the configuration file",
- ];
- for help in helpables {
+ "help" | "--help" | "-h" =>
+ for help in HELPABLES_BUILTIN_CONFIG.iter() {
println!("{}", help);
- }
- }
+ },
"refresh" => Config::refresh(),
_ => println!("invalid arguments provided"),
},
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index f5069fc..dc9a008 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -2,4 +2,5 @@
// SPDX-License-Identifier: GPL-3.0-only
pub mod log;
+pub mod sort;
pub mod system;
diff --git a/src/utils/sort.rs b/src/utils/sort.rs
new file mode 100644
index 0000000..131fa55
--- /dev/null
+++ b/src/utils/sort.rs
@@ -0,0 +1,6 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub fn sort_vec_alphabetically(vec: &mut Vec<&str>) {
+ vec.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));
+}