Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected virtual void GenerateArguments(
{
var enumNames = ExtractNamesFromEnum(arg.UnderlyingType);
var description = enumNames.Any()
? $"{arg.Description}\nAllowed values are: {string.Join(", ", enumNames)}"
? $"{arg.Description}\nAllowed values are: {string.Join(", ", enumNames)}."
: arg.Description;

var wrappedDescription = IndentWriter?.Write(description);
Expand Down Expand Up @@ -228,7 +228,7 @@ protected virtual void GenerateOptions(
{
var enumNames = ExtractNamesFromEnum(opt.UnderlyingType);
var description = enumNames.Any()
? $"{opt.Description}\nAllowed values are: {string.Join(", ", enumNames)}"
? $"{opt.Description}\nAllowed values are: {string.Join(", ", enumNames)}."
: opt.Description;

var wrappedDescription = IndentWriter?.Write(description);
Expand Down
28 changes: 14 additions & 14 deletions src/CommandLineUtils/Properties/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace McMaster.Extensions.CommandLineUtils
internal static class Strings
{
public const string DefaultHelpTemplate = "-?|-h|--help";
public const string DefaultHelpOptionDescription = "Show help information";
public const string DefaultHelpOptionDescription = "Show help information.";

public const string DefaultVersionTemplate = "--version";
public const string DefaultVersionOptionDescription = "Show version information";
public const string DefaultVersionOptionDescription = "Show version information.";

public const string IsNullOrEmpty = "Value is null or empty.";

Expand All @@ -24,26 +24,26 @@ public const string NoValueTypesMustBeBoolean
= "Cannot specify CommandOptionType.NoValue unless the type is boolean.";

public const string AmbiguousOnExecuteMethod
= "Could not determine which 'OnExecute' or 'OnExecuteAsync' method to use. Multiple methods with this name were found";
= "Could not determine which 'OnExecute' or 'OnExecuteAsync' method to use. Multiple methods with this name were found.";

public const string NoOnExecuteMethodFound
= "No method named 'OnExecute' or 'OnExecuteAsync' could be found";
= "No method named 'OnExecute' or 'OnExecuteAsync' could be found.";

public const string ConventionRequiresModel
= "This convention cannot be used on a command that does not implement " + nameof(IModelAccessor);
= "This convention cannot be used on a command that does not implement " + nameof(IModelAccessor) + ".";

public static string InvalidOnExecuteReturnType(string methodName)
=> methodName + " must have a return type of int or void, or if the method is async, Task<int> or Task.";

public static string InvalidOnValidateReturnType(Type modelType)
=> $"The OnValidate method on {modelType.FullName} must return {typeof(ValidationResult).FullName}";
=> $"The OnValidate method on {modelType.FullName} must return {typeof(ValidationResult).FullName}.";

public static string CannotDetermineOptionType(PropertyInfo member)
=> $"Could not automatically determine the {nameof(CommandOptionType)} for type {member.PropertyType.FullName}. " +
$"Set the {nameof(OptionAttribute.OptionType)} on the {nameof(OptionAttribute)} declaration for {member.DeclaringType.FullName}.{member.Name}.";

public static string OptionNameIsAmbiguous(string optionName, PropertyInfo first, PropertyInfo second)
=> $"Ambiguous option name. Both {first.DeclaringType.FullName}.{first.Name} and {second.DeclaringType.FullName}.{second.Name} produce a CommandOption with the name '{optionName}'";
=> $"Ambiguous option name. Both {first.DeclaringType.FullName}.{first.Name} and {second.DeclaringType.FullName}.{second.Name} produce a CommandOption with the name '{optionName}'.";

public static string DuplicateSubcommandName(string commandName)
=> $"The subcommand name '{commandName}' has already been been specified. Subcommand names must be unique.";
Expand All @@ -58,19 +58,19 @@ public static string BothOptionAndVersionOptionAttributesCannotBeSpecified(Prope
=> $"Cannot specify both {nameof(OptionAttribute)} and {nameof(VersionOptionAttribute)} on property {prop.DeclaringType.Name}.{prop.Name}.";

internal static string UnsupportedParameterTypeOnMethod(string methodName, ParameterInfo methodParam)
=> $"Unsupported type on {methodName} '{methodParam.ParameterType.FullName}' on parameter {methodParam.Name}";
=> $"Unsupported type on {methodName} '{methodParam.ParameterType.FullName}' on parameter {methodParam.Name}.";

public static string BothHelpOptionAndVersionOptionAttributesCannotBeSpecified(PropertyInfo prop)
=> $"Cannot specify both {nameof(HelpOptionAttribute)} and {nameof(VersionOptionAttribute)} on property {prop.DeclaringType.Name}.{prop.Name}.";

public static string DuplicateArgumentPosition(int order, PropertyInfo first, PropertyInfo second)
=> $"Duplicate value for argument order. Both {first.DeclaringType.FullName}.{first.Name} and {second.DeclaringType.FullName}.{second.Name} have set Order = {order}";
=> $"Duplicate value for argument order. Both {first.DeclaringType.FullName}.{first.Name} and {second.DeclaringType.FullName}.{second.Name} have set Order = {order}.";

public static string OnlyLastArgumentCanAllowMultipleValues(string? lastArgName)
=> $"The last argument '{lastArgName}' accepts multiple values. No more argument can be added.";

public static string CannotDetermineParserType(Type type)
=> $"Could not automatically determine how to convert string values into {type.FullName}";
=> $"Could not automatically determine how to convert string values into {type.FullName}.";

public static string CannotDetermineParserType(PropertyInfo prop)
=> $"Could not automatically determine how to convert string values into {prop.PropertyType.FullName} on property {prop.DeclaringType.Name}.{prop.Name}.";
Expand All @@ -94,15 +94,15 @@ public static string RemainingArgsPropsIsUnassignable(Type type)
=> $"The RemainingArguments property type on {type.Name} is invalid. It must be assignable from string[].";

public static string NoPropertyOrMethodFound(string memberName, Type type)
=> $"Could not find a property or method named {memberName} on type {type.FullName}";
=> $"Could not find a property or method named {memberName} on type {type.FullName}.";

public static string NoParameterTypeRegistered(Type modelType, Type paramType)
=> $"The constructor of type '{modelType}' contains the parameter of type '{paramType}' is not registered, Ensure the type '{paramType}' are registered in additional services with CommandLineApplication.Conventions.UseConstructorInjection(IServiceProvider additionalServices)";
=> $"The constructor of type '{modelType}' contains the parameter of type '{paramType}' is not registered, Ensure the type '{paramType}' are registered in additional services with CommandLineApplication.Conventions.UseConstructorInjection(IServiceProvider additionalServices).";

public static string NoAnyPublicConstuctorFound(Type modelType)
=> $"Could not find any public constructors of type '{modelType}'";
=> $"Could not find any public constructors of type '{modelType}'.";

public static string NoMatchedConstructorFound(Type modelType)
=> $"Could not found any matched constructors of type '{modelType}'";
=> $"Could not found any matched constructors of type '{modelType}'.";
}
}
60 changes: 30 additions & 30 deletions test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,26 @@ public void ShowHelp()
{
var app = new CommandLineApplication();
app.HelpOption();
app.Option("--strOpt <E>", "str option desc", CommandOptionType.SingleValue);
app.Option<int>("--intOpt <E>", "int option desc", CommandOptionType.SingleValue);
app.Option<SomeEnum>("--enumOpt <E>", "enum option desc", CommandOptionType.SingleValue);
app.Argument("SomeStringArgument", "string arg desc");
app.Argument<SomeEnum>("SomeEnumArgument", "enum arg desc");
app.Option("--strOpt <E>", "str option desc.", CommandOptionType.SingleValue);
app.Option<int>("--intOpt <E>", "int option desc.", CommandOptionType.SingleValue);
app.Option<SomeEnum>("--enumOpt <E>", "enum option desc.", CommandOptionType.SingleValue);
app.Argument("SomeStringArgument", "string arg desc.");
app.Argument<SomeEnum>("SomeEnumArgument", "enum arg desc.");
var helpText = GetHelpText(app);

Assert.Equal(@"Usage: [options] <SomeStringArgument> <SomeEnumArgument>

Arguments:
SomeStringArgument string arg desc
SomeEnumArgument enum arg desc
Allowed values are: None, Normal, Extreme
SomeStringArgument string arg desc.
SomeEnumArgument enum arg desc.
Allowed values are: None, Normal, Extreme.

Options:
-?|-h|--help Show help information
--strOpt <E> str option desc
--intOpt <E> int option desc
--enumOpt <E> enum option desc
Allowed values are: None, Normal, Extreme
-?|-h|--help Show help information.
--strOpt <E> str option desc.
--intOpt <E> int option desc.
--enumOpt <E> enum option desc.
Allowed values are: None, Normal, Extreme.

",
helpText,
Expand All @@ -144,16 +144,16 @@ public void ShowHelpFromAttributes()
Assert.Equal(@"Usage: test [options] <SomeStringArgument> <SomeEnumArgument>

Arguments:
SomeStringArgument string arg desc
SomeEnumArgument enum arg desc
Allowed values are: None, Normal, Extreme
SomeStringArgument string arg desc.
SomeEnumArgument enum arg desc.
Allowed values are: None, Normal, Extreme.

Options:
-strOpt|--str-opt <STR_OPT> str option desc
-intOpt|--int-opt <INT_OPT> int option desc
-enumOpt|--verbosity <VERBOSITY> enum option desc
Allowed values are: None, Normal, Extreme
-?|-h|--help Show help information
-strOpt|--str-opt <STR_OPT> str option desc.
-intOpt|--int-opt <INT_OPT> int option desc.
-enumOpt|--verbosity <VERBOSITY> enum option desc.
Allowed values are: None, Normal, Extreme.
-?|-h|--help Show help information.

",
helpText,
Expand All @@ -162,27 +162,27 @@ SomeEnumArgument enum arg desc

public class MyApp
{
[Option(ShortName = "strOpt", Description = "str option desc")]
[Option(ShortName = "strOpt", Description = "str option desc.")]
public string strOpt { get; set; }

[Option(ShortName = "intOpt", Description = "int option desc")]
[Option(ShortName = "intOpt", Description = "int option desc.")]
public int intOpt { get; set; }

[Option(ShortName = "enumOpt", Description = "enum option desc")]
[Option(ShortName = "enumOpt", Description = "enum option desc.")]
public SomeEnum Verbosity { get; set; }

[Argument(0, Description = "string arg desc")]
[Argument(0, Description = "string arg desc.")]
public string SomeStringArgument { get; set; }

[Argument(1, Description = "enum arg desc")]
[Argument(1, Description = "enum arg desc.")]
public SomeEnum SomeEnumArgument { get; set; }
}

[Theory]
[InlineData("-h", "-h", " -h Show help information", " Subcommand ")]
[InlineData("--help", "--help", " --help Show help information", " Subcommand ")]
[InlineData("-?", "-?", " -? Show help information", " Subcommand ")]
[InlineData(null, "-?|-h|--help", " -?|-h|--help Show help information", " Subcommand ")]
[InlineData("-h", "-h", " -h Show help information.", " Subcommand ")]
[InlineData("--help", "--help", " --help Show help information.", " Subcommand ")]
[InlineData("-?", "-?", " -? Show help information.", " Subcommand ")]
[InlineData(null, "-?|-h|--help", " -?|-h|--help Show help information.", " Subcommand ")]
public void ShowHelpWithSubcommands(string helpOption, string expectedHintText, string expectedOptionsText,
string expectedCommandsText)
{
Expand Down