Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
        public static bool TryParseDisplay(
            IEnumerable <string> values,
            string optionName,
            out ContentDisplayStyle?contentDisplayStyle,
            out PathDisplayStyle?pathDisplayStyle,
            out LineDisplayOptions lineDisplayOptions,
            out LineContext lineContext,
            out DisplayParts displayParts,
            out ImmutableArray <FileProperty> fileProperties,
            out string?indent,
            out string?separator,
            out bool noAlign,
            OptionValueProvider?contentDisplayStyleProvider = null,
            OptionValueProvider?pathDisplayStyleProvider    = null)
        {
            contentDisplayStyle = null;
            pathDisplayStyle    = null;
            lineDisplayOptions  = LineDisplayOptions.None;
            lineContext         = default;
            displayParts        = DisplayParts.None;
            fileProperties      = ImmutableArray <FileProperty> .Empty;
            indent    = null;
            separator = null;
            noAlign   = false;

            ImmutableArray <FileProperty> .Builder?builder = null;

            foreach (string value in values)
            {
                int index = value.IndexOf('=');

                if (index >= 0)
                {
                    string key    = value.Substring(0, index);
                    string value2 = value.Substring(index + 1);

                    if (key == "t")
                    {
                        LogHelpers.WriteObsoleteWarning($"Value '{key}' is obsolete. "
                                                        + $"Use value '{OptionValues.Display_Context.HelpValue}' instead.");

                        key = OptionValues.Display_Context.ShortKey;
                    }
                    else if (key == "ta")
                    {
                        LogHelpers.WriteObsoleteWarning($"Value '{key}' is obsolete. "
                                                        + $"Use value '{OptionValues.Display_ContextAfter.HelpValue}' instead.");

                        key = OptionValues.Display_ContextAfter.ShortKey;
                    }
                    else if (key == "tb")
                    {
                        LogHelpers.WriteObsoleteWarning($"Value '{key}' is obsolete. "
                                                        + $"Use value '{OptionValues.Display_ContextBefore.HelpValue}' instead.");

                        key = OptionValues.Display_ContextBefore.ShortKey;
                    }

                    if (OptionValues.Display_Content.IsKeyOrShortKey(key))
                    {
                        if (!TryParseAsEnum(
                                value2,
                                optionName,
                                out ContentDisplayStyle contentDisplayStyle2,
                                provider: contentDisplayStyleProvider))
                        {
                            return(false);
                        }

                        contentDisplayStyle = contentDisplayStyle2;
                    }
                    else if (OptionValues.Display_Path.IsKeyOrShortKey(key))
                    {
                        if (!TryParseAsEnum(
                                value2,
                                optionName,
                                out PathDisplayStyle pathDisplayStyle2,
                                provider: pathDisplayStyleProvider))
                        {
                            return(false);
                        }

                        pathDisplayStyle = pathDisplayStyle2;
                    }
                    else if (OptionValues.Display_Indent.IsKeyOrShortKey(key))
                    {
                        indent = value2;
                    }
                    else if (OptionValues.Display_Separator.IsKeyOrShortKey(key))
                    {
                        separator = RegexEscape.ConvertCharacterEscapes(value2);
                    }
                    else if (OptionValues.Display_Context.IsKeyOrShortKey(key))
                    {
                        if (!TryParseCount(value2, OptionNames.Display, out int count, value))
                        {
                            return(false);
                        }

                        lineContext = new LineContext(count);
                    }
                    else if (OptionValues.Display_ContextBefore.IsKeyOrShortKey(key))
                    {
                        if (!TryParseCount(value2, OptionNames.Display, out int before, value))
                        {
                            return(false);
                        }

                        lineContext = lineContext.WithBefore(before);
                    }
                    else if (OptionValues.Display_ContextAfter.IsKeyOrShortKey(key))
                    {
                        if (!TryParseCount(value2, OptionNames.Display, out int after, value))
                        {
                            return(false);
                        }

                        lineContext = lineContext.WithAfter(after);
                    }
                    else
                    {
                        WriteOptionError(value, optionName, OptionValueProviders.DisplayProvider);
                        return(false);
                    }
                }
                else if (OptionValues.Display_Summary.IsValueOrShortValue(value))
                {
                    displayParts |= DisplayParts.Summary;
                }
                else if (OptionValues.Display_Count.IsValueOrShortValue(value))
                {
                    displayParts |= DisplayParts.Count;
                }
                else if (OptionValues.Display_CreationTime.IsValueOrShortValue(value))
                {
                    (builder ??= ImmutableArray.CreateBuilder <FileProperty>()).Add(FileProperty.CreationTime);
                }
                else if (OptionValues.Display_ModifiedTime.IsValueOrShortValue(value))
                {
                    (builder ??= ImmutableArray.CreateBuilder <FileProperty>()).Add(FileProperty.ModifiedTime);
                }
                else if (OptionValues.Display_Size.IsValueOrShortValue(value))
                {
                    (builder ??= ImmutableArray.CreateBuilder <FileProperty>()).Add(FileProperty.Size);
                }
                else if (OptionValues.Display_LineNumber.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.IncludeLineNumber;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else if (OptionValues.Display_NoAlign.IsValueOrShortValue(value))
                {
                    noAlign = true;
                }
                else
                {
                    WriteOptionError(value, optionName, OptionValueProviders.DisplayProvider);
                    return(false);
                }
            }

            if (builder != null)
            {
                fileProperties = builder.ToImmutableArray();
            }

            return(true);
        }
Example #4
0
        public static bool TryParseDisplay(
            IEnumerable <string> values,
            string optionName,
            out ContentDisplayStyle?contentDisplayStyle,
            out PathDisplayStyle?pathDisplayStyle,
            out LineDisplayOptions lineDisplayOptions,
            out DisplayParts displayParts,
            out ImmutableArray <FileProperty> fileProperties,
            out string indent,
            out string separator,
            OptionValueProvider contentDisplayStyleProvider = null,
            OptionValueProvider pathDisplayStyleProvider    = null)
        {
            contentDisplayStyle = null;
            pathDisplayStyle    = null;
            lineDisplayOptions  = LineDisplayOptions.None;
            displayParts        = DisplayParts.None;
            fileProperties      = ImmutableArray <FileProperty> .Empty;
            indent    = null;
            separator = null;

            ImmutableArray <FileProperty> .Builder builder = null;

            foreach (string value in values)
            {
                int index = value.IndexOf('=');

                if (index >= 0)
                {
                    string key    = value.Substring(0, index);
                    string value2 = value.Substring(index + 1);

                    if (OptionValues.Display_Content.IsKeyOrShortKey(key))
                    {
                        if (!TryParseAsEnum(value2, optionName, out ContentDisplayStyle contentDisplayStyle2, provider: contentDisplayStyleProvider))
                        {
                            return(false);
                        }

                        contentDisplayStyle = contentDisplayStyle2;
                    }
                    else if (OptionValues.Display_Path.IsKeyOrShortKey(key))
                    {
                        if (!TryParseAsEnum(value2, optionName, out PathDisplayStyle pathDisplayStyle2, provider: pathDisplayStyleProvider))
                        {
                            return(false);
                        }

                        pathDisplayStyle = pathDisplayStyle2;
                    }
                    else if (OptionValues.Display_Indent.IsKeyOrShortKey(key))
                    {
                        indent = value2;
                    }
                    else if (OptionValues.Display_Separator.IsKeyOrShortKey(key))
                    {
                        separator = value2;
                    }
                    else
                    {
                        ThrowException(value);
                    }
                }
                else if (OptionValues.Display_Summary.IsValueOrShortValue(value))
                {
                    displayParts |= DisplayParts.Summary;
                }
                else if (OptionValues.Display_Count.IsValueOrShortValue(value))
                {
                    displayParts |= DisplayParts.Count;
                }
                else if (OptionValues.Display_CreationTime.IsValueOrShortValue(value))
                {
                    (builder ?? (builder = ImmutableArray.CreateBuilder <FileProperty>())).Add(FileProperty.CreationTime);
                }
                else if (OptionValues.Display_ModifiedTime.IsValueOrShortValue(value))
                {
                    (builder ?? (builder = ImmutableArray.CreateBuilder <FileProperty>())).Add(FileProperty.ModifiedTime);
                }
                else if (OptionValues.Display_Size.IsValueOrShortValue(value))
                {
                    (builder ?? (builder = ImmutableArray.CreateBuilder <FileProperty>())).Add(FileProperty.Size);
                }
                else if (OptionValues.Display_LineNumber.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.IncludeLineNumber;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else if (OptionValues.Display_TrimLine.IsValueOrShortValue(value))
                {
                    lineDisplayOptions |= LineDisplayOptions.TrimLine;
                }
                else
                {
                    ThrowException(value);
                }
            }

            if (builder != null)
            {
                fileProperties = builder.ToImmutableArray();
            }

            return(true);

            void ThrowException(string value)
            {
                string helpText = OptionValueProviders.DisplayProvider.GetHelpText();

                throw new ArgumentException($"Option '{OptionNames.GetHelpText(optionName)}' has invalid value '{value}'. Allowed values: {helpText}.", nameof(values));
            }
        }
Example #5
0
 public bool Includes(DisplayParts parts) => (DisplayParts & parts) == parts;