CommandParser.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "CommandParser.h"
  2. #include "NewProjectCmd.h"
  3. #include "PlatformAddCmd.h"
  4. #include "BuildCmd.h"
  5. #include "ImportCmd.h"
  6. #include "PlayCmd.h"
  7. #include "EditCmd.h"
  8. namespace ToolCore
  9. {
  10. CommandParser::CommandParser(Context* context) : Object(context)
  11. {
  12. }
  13. CommandParser::~CommandParser()
  14. {
  15. }
  16. Command* CommandParser::Parse(const Vector<String>& arguments)
  17. {
  18. Command* cmd = NULL;
  19. for (unsigned i = 0; i < arguments.Size(); ++i)
  20. {
  21. if (arguments[i].Length())
  22. {
  23. String argument = arguments[i].ToLower();
  24. if (argument == "new")
  25. {
  26. cmd = new NewProjectCmd(context_);
  27. }
  28. else if (argument == "build")
  29. {
  30. cmd = new BuildCmd(context_);
  31. }
  32. else if (argument == "platform-add")
  33. {
  34. cmd = new PlatformAddCmd(context_);
  35. }
  36. else if (argument == "import")
  37. {
  38. cmd = new ImportCmd(context_);
  39. }
  40. else if (argument == "play")
  41. {
  42. cmd = new PlayCmd(context_);
  43. }
  44. else if (argument == "edit")
  45. {
  46. cmd = new EditCmd(context_);
  47. }
  48. }
  49. if (cmd)
  50. {
  51. if (cmd->Parse(arguments, i, errorMsg_))
  52. return cmd;
  53. cmd->ReleaseRef();
  54. break;
  55. }
  56. }
  57. return NULL;
  58. }
  59. }