CommandParser.cpp 1.0 KB

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