Default Values ​​for Lists / Arrays Using the Parser Library Command Line

Using the Parser library for the command line and having a list or array with a default value, the default value is printed as (default: System.String []). Is there a way to show the actual defaults?

So,

[OptionList('l', "languages", Separator = ',', DefaultValue = new []{"eng"})]
public IList<string> Languages { get; set; }

help text is printed as "(Default: System.String[]) ...". I would like him to say "(Default: { "eng" })".

+5
source share
1 answer

HelpText has suffered from the use of the generic formatting function from DefaultValue.

The problem was (last stable) on line 702 HelpText.cs :

if (option.HasDefaultValue)
{
  option.HelpText = "(Default: {0}) ".FormatLocal(option.DefaultValue) + option.HelpText;
}

( , ) ( ):

private static string FormatDefaultValue(object value)
{
    if (value is bool)
    {
        return value.ToLocalString().ToLowerInvariant();
    }

    if (value is string)
    {
        return value.ToLocalString();
    }

    var asEnumerable = value as IEnumerable;
    if (asEnumerable != null)
    {
        var builder = new StringBuilder();
        foreach (var item in asEnumerable)
        {
            builder.Append(item.ToLocalString());
            builder.Append(" ");
        }
        return builder.Length > 0 ? builder.ToString(0, builder.Length - 1) : string.Empty;
    }
    return value.ToLocalString();
}

:

git clone -b develop-1.9.8-beta https://github.com/gsscoder/commandline.git commandline-develop

, , . .

.

+2

All Articles