Skip to content

Commit

Permalink
Merge pull request #12 from faviann/master
Browse files Browse the repository at this point in the history
Moved the lowercasing of commands after overload processing
  • Loading branch information
mayuki authored Feb 5, 2020
2 parents 494484a + 4fb797b commit 0cc2504
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Cocona.Core/Command/CoconaCommandProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public CommandDescriptor CreateCommand(MethodInfo methodInfo, bool isSingleComma
var description = commandAttr?.Description ?? string.Empty;
var aliases = commandAttr?.Aliases ?? Array.Empty<string>();

if (_enableConvertCommandNameToLowerCase) commandName = ToCommandCase(commandName);

var isPrimaryCommand = primaryCommandAttr != null;
var isHidden = commandHiddenAttr != null;

Expand Down Expand Up @@ -253,6 +251,8 @@ public CommandDescriptor CreateCommand(MethodInfo methodInfo, bool isSingleComma
overloadDescriptors[i] = overloadDescriptor;
}
}

if (_enableConvertCommandNameToLowerCase) commandName = ToCommandCase(commandName);

var flags = ((isHidden) ? CommandFlags.Hidden : CommandFlags.None) |
((isSingleCommand || isPrimaryCommand) ? CommandFlags.Primary : CommandFlags.None);
Expand Down
11 changes: 11 additions & 0 deletions test/Cocona.Test/Command/CommandProvider/CommandOverloadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public void Multiple_UnknownOption()
var provider = new CoconaCommandProvider(new[] { typeof(TestCommand_Overload_Multiple_UnknownOption) });
Assert.Throws<CoconaException>(() => provider.GetCommandCollection());
}

[Fact]
public void Match_CommandName_LowerCase()
{
var provider = new CoconaCommandProvider(new[] { typeof(TestCommand_Overload_Single) }, enableConvertCommandNameToLowerCase: true);
var commands = provider.GetCommandCollection();
commands.Should().NotBeNull();
commands.All.Should().HaveCount(1);
commands.Primary.Should().NotBeNull();
commands.Primary.Overloads.Should().HaveCount(2);
}

class TestCommand_Overload_Single
{
Expand Down

0 comments on commit 0cc2504

Please sign in to comment.