mgrsh.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use easy_repl::{command, CommandStatus, Repl};
  2. use crate::syscall;
  3. pub fn mgr_shell() {
  4. let repl_bresult = Repl::builder()
  5. .description("admin shell")
  6. .prompt("[ M-Admin-Sh ] ")
  7. .add("hello", command! {
  8. "print hello",
  9. () => || {
  10. println!("hello!");
  11. Ok(CommandStatus::Done)
  12. }
  13. })
  14. .add("exec", command! {
  15. "run a command, without arguments",
  16. (shell: String) => |shell:String| {
  17. syscall::proc::shell_exec_cmd(shell);
  18. Ok(CommandStatus::Done)
  19. }
  20. })
  21. .build();
  22. let mut repl = match repl_bresult {
  23. Ok(t) => t,
  24. Err(err) => {
  25. println!("[ERROR] admin Shell Init Fatal Error: {:?}", err);
  26. return;
  27. }
  28. };
  29. let repl_run_result = repl.run();
  30. match repl_run_result {
  31. Ok(_) => {
  32. println!("Back to maintenance shell.");
  33. }
  34. Err(err) => {
  35. println!("[ERROR] admin shell crash by error: {:?}", err);
  36. println!("Back to maintenance shell.");
  37. }
  38. };
  39. }