You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.3 KiB
77 lines
2.3 KiB
use crate::builtins::{Builtin, BuiltinConfig};
|
|
use crate::error::ShellError;
|
|
use colored::Colorize;
|
|
|
|
pub struct Help;
|
|
|
|
impl Builtin for Help {
|
|
fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
|
|
let commands = "blahaj prints blahaj, styles: p, t
|
|
cd changes current working directory
|
|
change-prompt changes prompt style (default, bashlike, simpledirectory)
|
|
exit exits the shell
|
|
fetch prints out system information
|
|
help displays this command
|
|
logout current user gets logged out
|
|
ls lists contents of directory
|
|
open shows content of files
|
|
pwd shows path to current working directory
|
|
quote prints a random quote
|
|
segfault exits, but the elegant way
|
|
sus shows amogus
|
|
";
|
|
|
|
for line in commands.lines() {
|
|
println!(
|
|
"{}{}",
|
|
split_command(line)[0].bold(),
|
|
split_command(line)[1]
|
|
);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn split_command(commands: &str) -> Vec<&str> {
|
|
if !commands.trim_start().is_empty() {
|
|
let splitted_command = commands.trim_start().splitn(2, ' ').collect();
|
|
return splitted_command;
|
|
}
|
|
vec!["", ""]
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_split_command_split() {
|
|
let test_string1 = "Hallo, Marcel Davis 1&1.";
|
|
assert_eq!(
|
|
split_command(test_string1),
|
|
vec!["Hallo,", "Marcel Davis 1&1."]
|
|
);
|
|
|
|
let test_string2 = "Leiter1 23für Kundenzufriedenheit.";
|
|
assert_eq!(
|
|
split_command(test_string2),
|
|
vec!["Leiter1", "23für Kundenzufriedenheit."]
|
|
);
|
|
|
|
let test_string3 = "Wir# $%gehen erst wieder, wenn ihre Leitung läuft!";
|
|
assert_eq!(
|
|
split_command(test_string3),
|
|
vec!["Wir#", "$%gehen erst wieder, wenn ihre Leitung läuft!"]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_split_command_empty() {
|
|
assert_eq!(split_command(""), vec!["", ""]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_split_command_only_space() {
|
|
assert_eq!(split_command(" "), vec!["", ""]);
|
|
}
|
|
}
|