CommandParser.cpp 1.3 KB

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