diff --git a/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs b/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs index 0e2b7df1..c64381b3 100644 --- a/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs +++ b/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs @@ -426,6 +426,11 @@ private string[] ExtractNamesFromEnum(Type? type) return ExtractNamesFromEnum(wrappedType2); } + if (ReflectionHelper.IsEnumerableType(type, out var wrappedEnumerableType)) + { + return ExtractNamesFromEnum(wrappedType2); + } + if (type.IsEnum) { return Enum.GetNames(type); diff --git a/src/CommandLineUtils/Internal/ReflectionHelper.cs b/src/CommandLineUtils/Internal/ReflectionHelper.cs index 07b6daec..e022390a 100644 --- a/src/CommandLineUtils/Internal/ReflectionHelper.cs +++ b/src/CommandLineUtils/Internal/ReflectionHelper.cs @@ -158,6 +158,15 @@ public static bool IsSpecialTupleType(Type type, [NotNullWhen(true)] out Type? w return result; } + public static bool IsEnumerableType(Type type, [NotNullWhen(true)] out Type? wrappedType) + { + var result = type.IsGenericType && + type.IsAssignableTo(typeof(IEnumerable<>)); + wrappedType = result ? type.GenericTypeArguments[1] : null; + + return result; + } + private static IEnumerable GetAllMembers(Type type) { while (type != null) diff --git a/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs b/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs index 9fdd88b8..42b7b91f 100644 --- a/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs +++ b/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs @@ -119,6 +119,7 @@ public void ShowHelp() }); app.Option<(bool, SomeEnum)>("--enumOpt3 ", "nullable enum option desc.", CommandOptionType.SingleOrNoValue); app.Option("--enumOpt4 ", "nullable enum option desc.", CommandOptionType.SingleOrNoValue); + app.Option("--enumOpt5 ", "multiple enum option desc.", CommandOptionType.MultipleValue); app.Argument("SomeStringArgument", "string arg desc."); app.Argument("RestrictedStringArgument", "restricted string arg desc.", a => a.IsRequired().Accepts().Values("Foo", "Bar")); app.Argument("DefaultValStringArgument", "string arg with default value desc.", a => a.DefaultValue = "Foo"); @@ -164,6 +165,8 @@ SomeNullableEnumArgument nullable enum arg desc. Allowed values are: None, Normal, Extreme. --enumOpt4[:] nullable enum option desc. Allowed values are: None, Normal, Extreme. + --enumOpt5[:] multiple enum option desc. + Allowed values are: None, Normal, Extreme. ", helpText,