public bool TryParse(ReplaceCommandOptions options) { var baseOptions = (CommonFindCommandOptions)options; if (!TryParse(baseOptions)) { return(false); } options = (ReplaceCommandOptions)baseOptions; if (!TryParseProperties(Ask, Name, options)) { return(false); } if (!TryParseAsEnumFlags(Highlight, OptionNames.Highlight, out HighlightOptions highlightOptions, defaultValue: HighlightOptions.Replacement, provider: OptionValueProviders.ReplaceHighlightOptionsProvider)) { return(false); } if (!FilterParser.TryParse(Content, OptionNames.Content, OptionValueProviders.PatternOptionsWithoutGroupAndPartAndNegativeProvider, out Filter contentFilter)) { return(false); } if (!TryParseReplacement(Replacement, out string replacement)) { return(false); } if (!DelegateFactory.TryCreateMatchEvaluator(Evaluator, out MatchEvaluator matchEvaluator)) { return(false); } if (replacement != null && matchEvaluator != null) { WriteError($"Options '{OptionNames.GetHelpText(OptionNames.Replacement)}' and '{OptionNames.GetHelpText(OptionNames.Evaluator)}' cannot be set both at the same time."); return(false); } if (!TryParseReplaceOptions(Modify, OptionNames.Modify, replacement, matchEvaluator, out ReplaceOptions replaceOptions)) { return(false); } if (!TryParseMaxCount(MaxCount, out int maxMatchesInFile, out int maxMatches, out int maxMatchingFiles)) { return(false); } ContentDisplayStyle contentDisplayStyle; PathDisplayStyle pathDisplayStyle; if (!TryParseDisplay( values: Display, optionName: OptionNames.Display, contentDisplayStyle: out ContentDisplayStyle? contentDisplayStyle2, pathDisplayStyle: out PathDisplayStyle? pathDisplayStyle2, lineDisplayOptions: out LineDisplayOptions lineDisplayOptions, displayParts: out DisplayParts displayParts, fileProperties: out ImmutableArray <FileProperty> fileProperties, indent: out string indent, separator: out string separator, contentDisplayStyleProvider: OptionValueProviders.ContentDisplayStyleProvider_WithoutUnmatchedLines, pathDisplayStyleProvider: OptionValueProviders.PathDisplayStyleProvider)) { return(false); } if (contentDisplayStyle2 != null) { if (options.AskMode == AskMode.Value && contentDisplayStyle2 == ContentDisplayStyle.AllLines) { WriteError($"Option '{OptionNames.GetHelpText(OptionNames.Display)}' cannot have value '{OptionValueProviders.ContentDisplayStyleProvider.GetValue(nameof(ContentDisplayStyle.AllLines)).HelpValue}' when option '{OptionNames.GetHelpText(OptionNames.Ask)}' has value '{OptionValueProviders.AskModeProvider.GetValue(nameof(AskMode.Value)).HelpValue}'."); return(false); } contentDisplayStyle = contentDisplayStyle2.Value; } else if (Input != null) { contentDisplayStyle = ContentDisplayStyle.AllLines; } else { contentDisplayStyle = ContentDisplayStyle.Line; } pathDisplayStyle = pathDisplayStyle2 ?? PathDisplayStyle.Full; if (pathDisplayStyle == PathDisplayStyle.Relative && options.Paths.Length > 1 && options.SortOptions != null) { pathDisplayStyle = PathDisplayStyle.Full; } options.Format = new OutputDisplayFormat( contentDisplayStyle: contentDisplayStyle, pathDisplayStyle: pathDisplayStyle, lineOptions: lineDisplayOptions, displayParts: displayParts, fileProperties: fileProperties, indent: indent, separator: separator); options.HighlightOptions = highlightOptions; options.ContentFilter = contentFilter; options.ReplaceOptions = replaceOptions; options.Input = Input; options.DryRun = DryRun; options.MaxMatchesInFile = maxMatchesInFile; options.MaxMatches = maxMatches; options.MaxMatchingFiles = maxMatchingFiles; options.ModifyOptions = ModifyOptions.Default; return(true); }
public bool TryParse(RenameCommandOptions options) { var baseOptions = (DeleteOrRenameCommandOptions)options; if (!TryParse(baseOptions)) { return(false); } options = (RenameCommandOptions)baseOptions; if (!TryParseHighlightOptions( Highlight, out HighlightOptions highlightOptions, defaultValue: HighlightOptions.Replacement, provider: OptionValueProviders.RenameHighlightOptionsProvider)) { return(false); } if (!FilterParser.TryParse( Name, OptionNames.Name, OptionValueProviders.PatternOptionsWithoutGroupAndNegativeProvider, out Filter? nameFilter, out FileNamePart namePart, namePartProvider: OptionValueProviders.NamePartKindProvider_WithoutFullName)) { return(false); } if (!FilterParser.TryParse( Content, OptionNames.Content, OptionValueProviders.PatternOptionsWithoutPartProvider, out Filter? contentFilter, allowNull: true)) { return(false); } if (!TryParseReplacement(Replacement, out string?replacement, out MatchEvaluator? matchEvaluator)) { return(false); } if (matchEvaluator == null && Evaluator != null) { LogHelpers.WriteObsoleteWarning( $"Option '{OptionNames.GetHelpText(OptionNames.Evaluator)}' is obsolete. " + $"Use option '{OptionNames.GetHelpText(OptionNames.Replacement)}' instead."); if (!DelegateFactory.TryCreateFromAssembly(Evaluator, typeof(string), typeof(Match), out matchEvaluator)) { return(false); } } if (!TryParseReplaceOptions( Modify, OptionNames.Modify, replacement, matchEvaluator, out ReplaceOptions? replaceOptions)) { return(false); } if (!TryParseAsEnum( Conflict, OptionNames.Conflict, out ConflictResolution conflictResolution, defaultValue: ConflictResolution.Ask, provider: OptionValueProviders.ConflictResolutionProvider_WithoutSuffix)) { return(false); } if (!TryParseDisplay( values: Display, optionName: OptionNames.Display, contentDisplayStyle: out ContentDisplayStyle? contentDisplayStyle, pathDisplayStyle: out PathDisplayStyle? pathDisplayStyle, lineDisplayOptions: out LineDisplayOptions lineDisplayOptions, lineContext: out LineContext lineContext, displayParts: out DisplayParts displayParts, fileProperties: out ImmutableArray <FileProperty> fileProperties, indent: out string?indent, separator: out string?separator, noAlign: out bool noAlign, contentDisplayStyleProvider: OptionValueProviders.ContentDisplayStyleProvider, pathDisplayStyleProvider: OptionValueProviders.PathDisplayStyleProvider_Rename)) { return(false); } if (pathDisplayStyle == PathDisplayStyle.Relative && options.Paths.Length > 1 && options.SortOptions != null) { pathDisplayStyle = PathDisplayStyle.Full; } options.Format = new OutputDisplayFormat( contentDisplayStyle: contentDisplayStyle ?? ContentDisplayStyle.Omit, pathDisplayStyle: pathDisplayStyle ?? PathDisplayStyle.Full, lineOptions: lineDisplayOptions, lineContext: lineContext, displayParts: displayParts, fileProperties: fileProperties, indent: indent, separator: separator, alignColumns: !noAlign); options.HighlightOptions = highlightOptions; options.SearchTarget = GetSearchTarget(); options.ReplaceOptions = replaceOptions; options.AskMode = (Ask) ? AskMode.File : AskMode.None; options.DryRun = DryRun; options.NameFilter = nameFilter; options.NamePart = namePart; options.ContentFilter = contentFilter; options.MaxMatchingFiles = MaxCount; options.ConflictResolution = conflictResolution; options.Interactive = Interactive; return(true); }