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.

62 lines
2.1 KiB

2 years ago
  1. use colored::Colorize;
  2. use crate::builtins::{Builtin, BuiltinConfig};
  3. use crate::error::ShellError;
  4. pub struct Help;
  5. impl Builtin for Help {
  6. fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
  7. let commands = "cd changes current working directory
  8. change-prompt changes prompt style (default, bashlike, simpledirectory)
  9. exit exits the shell
  10. fetch prints out system information
  11. help displays this command
  12. logout current user gets logged out
  13. ls lists contents of directory
  14. open shows content of files
  15. pwd shows path to current working directory
  16. quote prints a random quote
  17. segfault exits, but the elegant way
  18. sus shows amogus
  19. ";
  20. for line in commands.lines() {
  21. println!("{}{}", split_command(line)[0].bold(), split_command(line)[1]);
  22. }
  23. Ok(())
  24. }
  25. }
  26. fn split_command(commands: &str) -> Vec<&str> {
  27. if commands.trim_start().len() >= 1 {
  28. let splitted_command = commands.trim_start().splitn(2, " ").collect();
  29. return splitted_command;
  30. }
  31. return vec!["", ""];
  32. }
  33. #[cfg(test)]
  34. mod tests {
  35. use super::*;
  36. #[test]
  37. fn test_split_command_split() {
  38. let test_string1 = "Hallo, Marcel Davis 1&1.";
  39. assert_eq!(split_command(test_string1), vec!["Hallo,", "Marcel Davis 1&1."]);
  40. let test_string2 = "Leiter1 23für Kundenzufriedenheit.";
  41. assert_eq!(split_command(test_string2), vec!["Leiter1", "23für Kundenzufriedenheit."]);
  42. let test_string3 = "Wir# $%gehen erst wieder, wenn ihre Leitung läuft!";
  43. assert_eq!(split_command(test_string3), vec!["Wir#", "$%gehen erst wieder, wenn ihre Leitung läuft!"]);
  44. }
  45. #[test]
  46. fn test_split_command_empty() {
  47. assert_eq!(split_command(""), vec!["", ""]);
  48. }
  49. #[test]
  50. fn test_split_command_only_space() {
  51. assert_eq!(split_command(" "), vec!["", ""]);
  52. }
  53. }