CommandLineOptionSet.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. namespace UnityEditor.TestRunner.CommandLineParser
  3. {
  4. internal class CommandLineOptionSet
  5. {
  6. ICommandLineOption[] m_Options;
  7. public CommandLineOptionSet(params ICommandLineOption[] options)
  8. {
  9. m_Options = options;
  10. }
  11. public void Parse(string[] args)
  12. {
  13. var i = 0;
  14. while (i < args.Length)
  15. {
  16. var arg = args[i];
  17. if (!arg.StartsWith("-"))
  18. {
  19. i++;
  20. continue;
  21. }
  22. string value = null;
  23. if (i + 1 < args.Length && !args[i + 1].StartsWith("-"))
  24. {
  25. value = args[i + 1];
  26. i++;
  27. }
  28. ApplyValueToMatchingOptions(arg, value);
  29. i++;
  30. }
  31. }
  32. private void ApplyValueToMatchingOptions(string argName, string value)
  33. {
  34. foreach (var option in m_Options)
  35. {
  36. if ("-" + option.ArgName == argName)
  37. {
  38. option.ApplyValue(value);
  39. }
  40. }
  41. }
  42. }
  43. }