private IReadOnlyList <ColoredString> FormatParameterInfo(ArgumentUsageInfo info, ArgumentSetUsageInfo setInfo)
        {
            // Select the colors we'll use.
            var          paramMetadataFgColor = UseColor ? new ConsoleColor?(ParameterMetadataForegroundColor) : null;
            ConsoleColor?paramSyntaxFgColor   = null;

            var entries = new List <ColoredString>
            {
                // Append parameter syntax info.
                new ColoredString(SimplifyParameterSyntax(info.DetailedSyntax), paramSyntaxFgColor)
            };

            // If both are present (and requested to be displayed), we combine the short name and
            // default value onto the same line.
            var parameterMetadata = new List <string>();

            // Append parameter's short name (if it has one).
            if (Options.HasFlag(UsageInfoOptions.IncludeParameterShortNameAliases) &&
                !string.IsNullOrEmpty(info.ShortName) &&
                !string.IsNullOrEmpty(setInfo.DefaultShortNamePrefix))
            {
                parameterMetadata.Add($"{Strings.UsageInfoShortForm} {setInfo.DefaultShortNamePrefix + info.ShortName}");
            }

            // Append the parameter's default value (if it has one, and if requested).
            if (Options.HasFlag(UsageInfoOptions.IncludeParameterDefaultValues) &&
                !string.IsNullOrEmpty(info.DefaultValue))
            {
                parameterMetadata.Add($"{Strings.UsageInfoDefaultValue} {info.DefaultValue}");
            }

            // Now append the short name and/or default value, if either
            // were present and accounted for.
            if (parameterMetadata.Count > 0)
            {
                entries.Add(new ColoredString(
                                string.Join(", ", parameterMetadata),
                                paramMetadataFgColor));
            }

            // Append the parameter's description (if it has one).
            if (!string.IsNullOrEmpty(info.Description))
            {
                entries.Add(info.Description);
            }

            return(entries);
        }
Exemplo n.º 2
0
 public void AddParameter(ArgumentUsageInfo info) => _allParameters.Add(info);
Exemplo n.º 3
0
        private IEnumerable <ColoredMultistring> FormatParameterInfo(
            ArgumentUsageInfo info,
            ArgumentSetUsageInfo setInfo,
            List <IEnumArgumentType> inlineDocumentedEnums)
        {
            var builder = new ColoredMultistringBuilder();

            var syntax = SimplifyParameterSyntax(info.DetailedSyntax);

            builder.Append(new ColoredString(syntax, ParameterNameForegroundColor));

            if (!string.IsNullOrEmpty(info.Description))
            {
                builder.Append(" - ");
                builder.Append(info.Description);
            }

            var metadataItems = new List <List <ColoredString> >();

            if (Options.HasFlag(UsageInfoOptions.IncludeParameterDefaultValues) &&
                !string.IsNullOrEmpty(info.DefaultValue))
            {
                metadataItems.Add(new List <ColoredString>
                {
                    new ColoredString(Strings.UsageInfoDefaultValue, ParameterMetadataForegroundColor),
                    " ",
                    info.DefaultValue
                });
            }

            // Append parameter's short name (if it has one).
            if (Options.HasFlag(UsageInfoOptions.IncludeParameterShortNameAliases) &&
                !string.IsNullOrEmpty(info.ShortName) &&
                !string.IsNullOrEmpty(setInfo.DefaultShortNamePrefix))
            {
                metadataItems.Add(new List <ColoredString>
                {
                    new ColoredString(Strings.UsageInfoShortForm, ParameterMetadataForegroundColor),
                    " ",
                    new ColoredString(setInfo.DefaultShortNamePrefix + info.ShortName, NameForegroundColor)
                });
            }

            if (metadataItems.Count > 0)
            {
                builder.Append(" [");
                builder.Append(metadataItems.InsertBetween(new List <ColoredString> {
                    ", "
                }).Flatten());
                builder.Append("]");
            }

            var formattedInfo = new List <ColoredMultistring> {
                builder.ToMultistring()
            };

            if (inlineDocumentedEnums?.Count > 0)
            {
                foreach (var entry in inlineDocumentedEnums.SelectMany(GetEnumValueEntries))
                {
                    var indentedEntry = new ColoredMultistring(new ColoredString[]
                    {
                        new string(' ', Section.DefaultIndent)
                    }.Concat(entry.Content));
                    formattedInfo.Add(indentedEntry);
                }
            }

            return(formattedInfo);
        }
Exemplo n.º 4
0
        public void StringArrayWithEmptyDefaultsArgument()
        {
            var arg = GetArgument(typeof(StringArrayWithEmptyDefaultArguments));

            var value = arg.EffectiveDefaultValue;
            value.Should().BeOfType(typeof(string[]));
            ((string[])value).Should().BeEmpty();

            arg.GetSyntaxHelp(s_defaultSetAttribute).Should().Be("[/Value[=<String>]]*");

            var usage = new ArgumentUsageInfo(new ArgumentSetAttribute(), arg);
            usage.DefaultValue.Should().BeNull();
        }
Exemplo n.º 5
0
        public void StringArrayArgument()
        {
            var arg = GetArgument(typeof(StringArrayArguments));

            var value = arg.EffectiveDefaultValue;
            value.Should().BeOfType(typeof(string[]));
            ((string[])value).Should().ContainInOrder("a", "b");

            arg.GetSyntaxHelp(s_defaultSetAttribute).Should().Be("[/Value[=<String>]]*");

            var usage = new ArgumentUsageInfo(new ArgumentSetAttribute(), arg);
            usage.DefaultValue.Should().Be("a b");
        }
Exemplo n.º 6
0
 public void NonEmptyStringArgument()
 {
     var arg = GetArgument(typeof(StringArgumentsThatMustBeNonEmpty));
     arg.EffectiveDefaultValue.Should().Be("");
     arg.DefaultValue.Should().Be("");
     arg.GetSyntaxHelp(s_defaultSetAttribute).Should().Be("[/Value=<String>]");
    
     var usageInfo = new ArgumentUsageInfo(new ArgumentSetAttribute(), arg);
     usageInfo.DefaultValue.Should().BeNull();
 }
Exemplo n.º 7
0
 public void BasicUsage()
 {
     var help = new ArgumentUsageInfo("Syntax", "Help", false);
     help.Syntax.Should().Be("Syntax");
     help.Description.Should().Be("Help");
 }