private static bool ResolvePositionalArgument(Context context, string arg) { if (Directory.Exists(arg)) { context.HotFolderPath = arg; return(true); } if (TryParseLocationAlias(arg, out var alias, out var locationIdentifier)) { AddLocationAlias(context, alias, locationIdentifier); return(true); } var match = SettingRegex.Match(arg); if (match.Success) { AddSetting(context, arg); return(true); } if (arg.Equals("/n", StringComparison.InvariantCultureIgnoreCase) || arg.Equals("-n", StringComparison.InvariantCultureIgnoreCase)) { context.DryRun = true; return(true); } return(false); }
private static void AddSetting(Context context, string value) { var match = SettingRegex.Match(value); if (!match.Success) { throw new ExpectedException($"'{value}' does not match a key=text or key=@pathToTextFile setting."); } var key = match.Groups["key"].Value; var text = match.Groups["text"].Value; var pathToText = match.Groups["pathToTextFile"].Value; context.Settings[key] = !string.IsNullOrWhiteSpace(pathToText) ? File.ReadAllText(pathToText) : text; }
private bool PositionalArgumentResolver(Context context, string arg) { if (RecursiveShortcuts.Contains(arg)) { Context.RecursiveSearch = true; return(true); } var match = SettingRegex.Match(arg); if (match.Success) { AddSetting(context, arg); return(true); } return(false); }
private static void AddSetting(Context context, string value) { var match = SettingRegex.Match(value); if (!match.Success) { throw new ExpectedException($"'{value}' does not match a pluginFolderName=key=text or pluginFolderName=key=@pathToTextFile setting."); } var pluginFolder = match.Groups["pluginFolder"].Value; var key = match.Groups["key"].Value; var text = match.Groups["text"].Value; var pathToText = match.Groups["pathToTextFile"].Value; if (!context.PluginSettings.TryGetValue(pluginFolder, out var settings)) { settings = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); context.PluginSettings[pluginFolder] = settings; } settings[key] = !string.IsNullOrWhiteSpace(pathToText) ? File.ReadAllText(pathToText) : text; }