2
0

Subsystem.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Text.RegularExpressions;
  2. namespace Renci.SshNet.TestTools.OpenSSH
  3. {
  4. public sealed class Subsystem
  5. {
  6. public Subsystem(string name, string command)
  7. {
  8. Name = name;
  9. Command = command;
  10. }
  11. public string Name { get; }
  12. public string Command { get; set; }
  13. public static Subsystem FromConfig(string value)
  14. {
  15. var subSystemValueRegex = new Regex(@"^\s*(?<name>[\S]+)\s+(?<command>.+?){1}\s*$");
  16. var match = subSystemValueRegex.Match(value);
  17. if (match.Success)
  18. {
  19. var nameGroup = match.Groups["name"];
  20. var commandGroup = match.Groups["command"];
  21. var name = nameGroup.Value;
  22. var command = commandGroup.Value;
  23. return new Subsystem(name, command);
  24. }
  25. throw new ArgumentException($"'{value}' not recognized as value for Subsystem.",
  26. nameof(value));
  27. }
  28. public void WriteTo(TextWriter writer)
  29. {
  30. if (writer is null)
  31. {
  32. throw new ArgumentNullException(nameof(writer));
  33. }
  34. writer.WriteLine(Name + "=" + Command);
  35. }
  36. }
  37. }