CommandParser.cpp 1.6 KB

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