CommandLineOption.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Linq;
  3. namespace UnityEditor.TestRunner.CommandLineParser
  4. {
  5. internal class CommandLineOption : ICommandLineOption
  6. {
  7. Action<string> m_ArgAction;
  8. public CommandLineOption(string argName, Action action)
  9. {
  10. ArgName = argName;
  11. m_ArgAction = s => action();
  12. }
  13. public CommandLineOption(string argName, Action<string> action)
  14. {
  15. ArgName = argName;
  16. m_ArgAction = action;
  17. }
  18. public CommandLineOption(string argName, Action<string[]> action)
  19. {
  20. ArgName = argName;
  21. m_ArgAction = s => action(SplitStringToArray(s));
  22. }
  23. public string ArgName { get; private set; }
  24. public void ApplyValue(string value)
  25. {
  26. m_ArgAction(value);
  27. }
  28. static string[] SplitStringToArray(string value)
  29. {
  30. if (string.IsNullOrEmpty(value))
  31. {
  32. return null;
  33. }
  34. return value.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
  35. }
  36. }
  37. }