CommandParser.cpp 1.2 KB

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