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

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