You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
950 B
29 lines
950 B
using System.Text.RegularExpressions; |
|
using OneOf; |
|
|
|
namespace StabilityMatrix.Core.Processes; |
|
|
|
public partial class ProcessArgs : OneOfBase<string, string[]> |
|
{ |
|
/// <inheritdoc /> |
|
private ProcessArgs(OneOf<string, string[]> input) |
|
: base(input) { } |
|
|
|
// Implicit conversions |
|
|
|
public static implicit operator ProcessArgs(string input) => new(input); |
|
|
|
public static implicit operator ProcessArgs(string[] input) => new(input); |
|
|
|
public static implicit operator string(ProcessArgs input) => |
|
input.Match(str => str, arr => string.Join(' ', arr.Select(ProcessRunner.Quote))); |
|
|
|
public static implicit operator string[](ProcessArgs input) => |
|
input.Match( |
|
str => ArgumentsRegex().Matches(str).Select(x => x.Value.Trim('"')).ToArray(), |
|
arr => arr |
|
); |
|
|
|
[GeneratedRegex("""[\"].+?[\"]|[^ ]+""", RegexOptions.IgnoreCase)] |
|
private static partial Regex ArgumentsRegex(); |
|
}
|
|
|