public RivetParameters Parse(IEnumerable<string> args) { var parameters = new RivetParameters(); var targetDirectoryArgument = args.FirstOrDefault(); if (string.IsNullOrEmpty(targetDirectoryArgument)) { parameters.DisplayHelpInformation = true; return parameters; } // extract target directory var targetDirectoryMatch = TargetDirectoryScanExpression.Match(targetDirectoryArgument); if (targetDirectoryMatch.Success) { parameters.TargetDirectory = targetDirectoryMatch.Value.TrimEnd('\\'); } else { // not an absolute path, treat as relative path parameters.TargetDirectory = Path.Combine(Environment.CurrentDirectory, targetDirectoryArgument.TrimEnd('\\')); } // extract variables foreach (var arg in args) { var matches = VariableScanExpression.Matches(arg); if (matches.Count == 1) { parameters.AddVariable(matches[0].Groups["key"].Value, matches[0].Groups["value"].Value); } } return parameters; }
private static void ExtractTargetDirectory(string targetDirectoryArgument, RivetParameters parameters) { var targetDirectoryMatch = TargetDirectoryScanExpression.Match(targetDirectoryArgument); if (targetDirectoryMatch.Success) { parameters.TargetDirectory = targetDirectoryMatch.Value.TrimEnd('\\'); } else { // not an absolute path, treat as relative path parameters.TargetDirectory = Path.Combine(Environment.CurrentDirectory, targetDirectoryArgument.TrimEnd('\\')); } }
public RivetParameters Parse(IEnumerable<string> args) { var parameters = new RivetParameters(); var targetDirectoryArgument = args.FirstOrDefault(); if (string.IsNullOrEmpty(targetDirectoryArgument)) { parameters.DisplayHelpInformation = true; return parameters; } // extract target directory ExtractTargetDirectory(targetDirectoryArgument, parameters); foreach (var arg in args) ExtractVariables(arg, parameters); return parameters; }
private static void ExtractVariables(string arg, RivetParameters parameters) { foreach (var component in arg.Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries)) { var matches = VariableScanExpression.Matches(component); if (matches.Count == 1) { parameters.AddVariable(matches[0].Groups["key"].Value, matches[0].Groups["value"].Value); } } }