CommandLine.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Created by xcbosa on 2023/1/31.
  3. //
  4. #pragma once
  5. #include "utils-private.h"
  6. namespace xc {
  7. namespace utils {
  8. class CommandLineWorker;
  9. class CommandLineCommand {
  10. friend CommandLineWorker;
  11. public:
  12. CommandLineCommand(string name, string usage, string message);
  13. virtual void evaluate(string userInputLine) const = 0;
  14. protected:
  15. string commandName;
  16. string commandUsage;
  17. string message;
  18. };
  19. class CommandLineStringCommand: public CommandLineCommand{
  20. public:
  21. CommandLineStringCommand(string commandName, string commandUsage, string message, int argCnt, function<void (vector<string>)> handler);
  22. void evaluate(string userInputLine) const override;
  23. private:
  24. int argCnt;
  25. function<void (vector<string>)> handler;
  26. };
  27. typedef CommandLineStringCommand strcmd;
  28. class CommandLineWorker {
  29. public:
  30. void workerLoop();
  31. void processCommand(string cmd);
  32. };
  33. } // xc
  34. } // utils