Skip to content

Commit ce715e8

Browse files
jcaillonnatemcmaster
authored andcommitted
Fix #207 - Additional command names are now case-sensitive (#210)
1 parent f0e4826 commit ce715e8

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
Enhancements:
6+
7+
Bugs fixed:
8+
* Fix [#207](https://github.com/natemcmaster/CommandLineUtils/issues/207) by [@jcaillon]: Option for the case sensitivity of command names
9+
310
## [v2.3.1]
411

512
Bugs fixed:

src/CommandLineUtils/CommandLineApplication.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public partial class CommandLineApplication : IServiceProvider, IDisposable
2929
private List<Action<ParseResult>> _onParsingComplete;
3030
internal readonly Dictionary<string, PropertyInfo> _shortOptions = new Dictionary<string, PropertyInfo>();
3131
internal readonly Dictionary<string, PropertyInfo> _longOptions = new Dictionary<string, PropertyInfo>();
32-
private readonly HashSet<string> _names = new HashSet<string>(StringComparer.Ordinal);
32+
private readonly HashSet<string> _names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
3333
private string _primaryCommandName;
3434
internal CommandLineContext _context;
3535
private IHelpTextGenerator _helpTextGenerator;
@@ -1003,7 +1003,6 @@ public void ShowRootCommandFullNameAndVersion()
10031003

10041004
internal bool MatchesName(string name)
10051005
{
1006-
// TODO: make this case-sensitive by default and add a parser setting
10071006
if (string.Equals(name, Name, StringComparison.OrdinalIgnoreCase))
10081007
{
10091008
return true;

src/CommandLineUtils/releasenotes.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<Project>
22
<PropertyGroup>
3+
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.3.2'">
4+
Bugs fixed:
5+
* @jcaillon: Option for the case sensitivity of command names.
6+
</PackageReleaseNotes>
37
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.3.1'">
48
Bugs fixed:
59
* Fix for InvalidOperationException thrown during help text generation on Mono

test/CommandLineUtils.Tests/CommandLineApplicationTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ public void CommandNameCanBeMatched()
4040
Assert.True(called);
4141
}
4242

43+
[Fact]
44+
public void CommandsNamesAreCaseInsensitive()
45+
{
46+
var app = new CommandLineApplication();
47+
var cmd = app.Command("TEST", c => {
48+
c.OnExecute(() => 5);
49+
});
50+
cmd.AddName("TE");
51+
52+
Assert.Equal(5, app.Execute("test"));
53+
Assert.Equal(5, app.Execute("TEST"));
54+
Assert.Equal(5, app.Execute("te"));
55+
Assert.Equal(5, app.Execute("TE"));
56+
}
57+
4358
[Fact]
4459
public void RemainingArgsArePassed()
4560
{

0 commit comments

Comments
 (0)