Skip to content

Commit 132a258

Browse files
authored
Merge pull request #67 from afernandes/hotfix/DisplayHelpCommand
Hotfix displayhelpcommand
2 parents 4ba3cca + 3005fa8 commit 132a258

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/ConsoleAppFramework/CommandHelpBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public CommandHelpDefinition CreateCommandHelpDefinition(MethodInfo method)
361361
}
362362

363363
return new CommandHelpDefinition(
364-
$"{method.DeclaringType!.Name.ToLower()}",
364+
method.DeclaringType.GetCustomAttribute<CommandAttribute>()?.CommandNames?.FirstOrDefault() ?? method.DeclaringType!.Name.ToLower(),
365365
command?.CommandNames ?? new[] { method.Name.ToLower() },
366366
parameterDefinitions.OrderBy(x => x.Index ?? int.MaxValue).ToArray(),
367367
command?.Description ?? String.Empty

tests/ConsoleAppFramework.Tests/CommandHelpTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public void BuildMethodListMessage()
1919
var builder = CreateCommandHelpBuilder();
2020
var expected = @$"
2121
Commands:
22-
commandhelptestlistmessagebatch hello
23-
commandhelptestlistmessagebatch YetAnotherHello
24-
commandhelptestlistmessagebatch HelloWithAliasWithDescription Description of command
22+
list-message-batch hello
23+
list-message-batch YetAnotherHello
24+
list-message-batch HelloWithAliasWithDescription Description of command
2525
".TrimStart();
2626

2727
var msg = builder.BuildMethodListMessage(new[] { typeof(CommandHelpTestListMessageBatch) }, out _);
@@ -36,9 +36,9 @@ public void BuildUsageMessage_Types()
3636
var expected = @"Usage: Nantoka <Command>
3737
3838
Commands:
39-
commandhelptestlistmessagebatch hello
40-
commandhelptestlistmessagebatch YetAnotherHello
41-
commandhelptestlistmessagebatch HelloWithAliasWithDescription Description of command
39+
list-message-batch hello
40+
list-message-batch YetAnotherHello
41+
list-message-batch HelloWithAliasWithDescription Description of command
4242
";
4343

4444
builder.BuildHelpMessage(new[] { typeof(CommandHelpTestListMessageBatch) }).Should().Be(expected);
@@ -342,6 +342,7 @@ public void CreateCommandHelp_BooleanWithTrueDefault_ShownWithoutValue()
342342
//}
343343
}
344344

345+
[Command("list-message-batch")]
345346
public class CommandHelpTestListMessageBatch : ConsoleAppBase
346347
{
347348
public void Hello()

0 commit comments

Comments
 (0)