public static AskReplacementWriter Create( ContentDisplayStyle contentDisplayStyle, string input, ReplaceOptions replaceOptions, Lazy <TextWriter> lazyWriter, ContentWriterOptions options, MatchOutputInfo outputInfo) { switch (contentDisplayStyle) { case ContentDisplayStyle.Value: case ContentDisplayStyle.ValueDetail: return(new AskValueReplacementWriter(input, replaceOptions, lazyWriter, options, outputInfo)); case ContentDisplayStyle.Line: return(new AskLineReplacementWriter(input, replaceOptions, lazyWriter, options)); case ContentDisplayStyle.UnmatchedLines: case ContentDisplayStyle.AllLines: throw new InvalidOperationException(); default: throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'."); } }
public static ContentWriter CreateReplace( ContentDisplayStyle contentDisplayStyle, string input, ReplaceOptions replaceOptions, ContentWriterOptions options, TextWriter?textWriter = null, MatchOutputInfo?outputInfo = null) { switch (contentDisplayStyle) { case ContentDisplayStyle.Value: case ContentDisplayStyle.ValueDetail: return(new ValueReplacementWriter(input, replaceOptions, options, textWriter, outputInfo)); case ContentDisplayStyle.Line: return(new LineReplacementWriter(input, replaceOptions, options, textWriter)); case ContentDisplayStyle.AllLines: return(new AllLinesReplacementWriter(input, replaceOptions, options, textWriter)); case ContentDisplayStyle.UnmatchedLines: throw new NotSupportedException($"Value '{contentDisplayStyle}' is not supported."); default: throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'."); } }
public static AskReplacementWriter Create( ContentDisplayStyle contentDisplayStyle, string input, IReplacer replacer, Lazy <TextWriter>?lazyWriter, ContentWriterOptions options, MatchOutputInfo?outputInfo, bool isInteractive, SpellcheckState?spellcheckState = null) { switch (contentDisplayStyle) { case ContentDisplayStyle.Value: case ContentDisplayStyle.ValueDetail: return(new AskValueReplacementWriter( input, replacer, lazyWriter, options, outputInfo, isInteractive, spellcheckState)); case ContentDisplayStyle.Line: return(new AskLineReplacementWriter(input, replacer, lazyWriter, options, isInteractive, spellcheckState)); case ContentDisplayStyle.UnmatchedLines: case ContentDisplayStyle.AllLines: throw new InvalidOperationException(); default: throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'."); } }
private ContentWriter CreateReplacementWriter( ContentDisplayStyle contentDisplayStyle, string input, IReplacer replacer, ContentWriterOptions options, TextWriter?textWriter = null, MatchOutputInfo?outputInfo = null) { return(ContentWriter.CreateReplace(contentDisplayStyle, input, replacer, options, textWriter, outputInfo, SpellcheckState)); }
public static ContentWriter CreateFind( ContentDisplayStyle contentDisplayStyle, string input, ContentWriterOptions options, IResultStorage?storage, MatchOutputInfo?outputInfo, ContentTextWriter?writer, bool ask = false) { if (ask) { switch (contentDisplayStyle) { case ContentDisplayStyle.Value: case ContentDisplayStyle.ValueDetail: return(new AskValueContentWriter(input, options, storage, outputInfo)); case ContentDisplayStyle.Line: return(new AskLineContentWriter(input, options, storage)); case ContentDisplayStyle.UnmatchedLines: case ContentDisplayStyle.AllLines: throw new InvalidOperationException(); default: throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'."); } } else { switch (contentDisplayStyle) { case ContentDisplayStyle.Value: case ContentDisplayStyle.ValueDetail: return(new ValueContentWriter(input, writer, options, storage, outputInfo)); case ContentDisplayStyle.Line: return(new LineContentWriter(input, writer, options, storage)); case ContentDisplayStyle.UnmatchedLines: return(new UnmatchedLineWriter(input, writer, options, storage)); case ContentDisplayStyle.AllLines: return(new AllLinesContentWriter(input, writer, options, storage)); default: throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'."); } } }
public static ContentWriter CreateFind( ContentDisplayStyle contentDisplayStyle, string input, ContentWriterOptions options, IResultStorage storage, MatchOutputInfo outputInfo, bool ask = false) { return(CreateFind(contentDisplayStyle, input, options, storage, outputInfo, ContentTextWriter.Default, ask)); }
public bool TryParse(FindCommandOptions options) { var baseOptions = (CommonFindCommandOptions)options; if (!TryParse(baseOptions)) { return(false); } options = (FindCommandOptions)baseOptions; if (!TryParseModifyOptions(Modify, OptionNames.Modify, out ModifyOptions? modifyOptions, out bool aggregateOnly)) { return(false); } OutputDisplayFormat format = options.Format; ContentDisplayStyle contentDisplayStyle = format.ContentDisplayStyle; PathDisplayStyle pathDisplayStyle = format.PathDisplayStyle; if (modifyOptions.HasAnyFunction && contentDisplayStyle == ContentDisplayStyle.ValueDetail) { contentDisplayStyle = ContentDisplayStyle.Value; } if (aggregateOnly) { ConsoleOut.Verbosity = Orang.Verbosity.Minimal; pathDisplayStyle = PathDisplayStyle.Omit; } options.ModifyOptions = modifyOptions; options.Format = new OutputDisplayFormat( contentDisplayStyle: contentDisplayStyle, pathDisplayStyle: pathDisplayStyle, lineOptions: format.LineOptions, lineContext: format.LineContext, displayParts: format.DisplayParts, fileProperties: format.FileProperties, indent: format.Indent, separator: format.Separator, includeBaseDirectory: format.IncludeBaseDirectory); return(true); }
public OutputDisplayFormat( ContentDisplayStyle contentDisplayStyle, PathDisplayStyle pathDisplayStyle = PathDisplayStyle.Full, LineDisplayOptions lineOptions = LineDisplayOptions.None, DisplayParts displayParts = DisplayParts.None, IEnumerable <FileProperty> fileProperties = null, string indent = null, string separator = null, bool includeBaseDirectory = false) { ContentDisplayStyle = contentDisplayStyle; PathDisplayStyle = pathDisplayStyle; LineOptions = lineOptions; DisplayParts = displayParts; FileProperties = fileProperties?.ToImmutableArray() ?? ImmutableArray <FileProperty> .Empty; Indent = indent ?? DefaultIndent; Separator = separator ?? Environment.NewLine; IncludeBaseDirectory = includeBaseDirectory; }
public OutputDisplayFormat( ContentDisplayStyle contentDisplayStyle, PathDisplayStyle pathDisplayStyle = PathDisplayStyle.Full, LineDisplayOptions lineOptions = LineDisplayOptions.None, LineContext lineContext = default, DisplayParts displayParts = DisplayParts.None, IEnumerable <FileProperty>?fileProperties = null, string?indent = null, string?separator = null, bool alignColumns = true) { ContentDisplayStyle = contentDisplayStyle; PathDisplayStyle = pathDisplayStyle; LineOptions = lineOptions; LineContext = lineContext; DisplayParts = displayParts; FileProperties = fileProperties?.ToImmutableArray() ?? ImmutableArray <FileProperty> .Empty; Indent = indent ?? DefaultIndent; Separator = separator; AlignColumns = alignColumns; }
public bool TryParse(FindCommandOptions options) { if (!TryParseAsEnum( Pipe, OptionNames.Pipe, out PipeMode pipeMode, PipeMode.None, OptionValueProviders.PipeMode)) { return(false); } if (pipeMode == PipeMode.None) { if (Console.IsInputRedirected) { PipeMode = PipeMode.Text; } } else { if (!Console.IsInputRedirected) { WriteError("Redirected/piped input is required " + $"when option '{OptionNames.GetHelpText(OptionNames.Pipe)}' is specified."); return(false); } PipeMode = pipeMode; } var baseOptions = (CommonFindCommandOptions)options; if (!TryParse(baseOptions)) { return(false); } options = (FindCommandOptions)baseOptions; if (!TryParseProperties(Ask, Name, options)) { return(false); } string?input = null; if (pipeMode != PipeMode.Paths && Console.IsInputRedirected) { if (options.ContentFilter == null) { WriteError($"Option '{OptionNames.GetHelpText(OptionNames.Content)}' is required " + "when redirected/piped input is used as a text to be searched."); return(false); } input = ConsoleHelpers.ReadRedirectedInput(); } EnumerableModifier <string>?modifier = null; #if DEBUG // --modifier if (Modifier.Any() && !TryParseModifier(Modifier, OptionNames.Modifier, out modifier)) { return(false); } #endif if (!TryParseModifyOptions( Modify, OptionNames.Modify, modifier, out ModifyOptions? modifyOptions, out bool aggregateOnly)) { return(false); } OutputDisplayFormat format = options.Format; ContentDisplayStyle contentDisplayStyle = format.ContentDisplayStyle; PathDisplayStyle pathDisplayStyle = format.PathDisplayStyle; if (modifyOptions.HasAnyFunction && contentDisplayStyle == ContentDisplayStyle.ValueDetail) { contentDisplayStyle = ContentDisplayStyle.Value; } options.Input = input; options.ModifyOptions = modifyOptions; options.AggregateOnly = aggregateOnly; options.Split = Split; options.Format = new OutputDisplayFormat( contentDisplayStyle: contentDisplayStyle, pathDisplayStyle: pathDisplayStyle, lineOptions: format.LineOptions, lineContext: format.LineContext, displayParts: format.DisplayParts, fileProperties: format.FileProperties, indent: format.Indent, separator: format.Separator, alignColumns: format.AlignColumns, includeBaseDirectory: format.IncludeBaseDirectory); return(true); }