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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

Enhancements:

Bugs fixed:
* Fix [#207](https://github.com/natemcmaster/CommandLineUtils/issues/207) by [@jcaillon]: Option for the case sensitivity of command names

## [v2.3.1]

Bugs fixed:
Expand Down
3 changes: 1 addition & 2 deletions src/CommandLineUtils/CommandLineApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class CommandLineApplication : IServiceProvider, IDisposable
private List<Action<ParseResult>> _onParsingComplete;
internal readonly Dictionary<string, PropertyInfo> _shortOptions = new Dictionary<string, PropertyInfo>();
internal readonly Dictionary<string, PropertyInfo> _longOptions = new Dictionary<string, PropertyInfo>();
private readonly HashSet<string> _names = new HashSet<string>(StringComparer.Ordinal);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than add a new API, I think I would rather just keep the code as is, but change this to StringComparer.OrdinalIgnoreCase. This was a new feature in 2.3 which hasn't seen much usage yet. Now that I think about it, I doubt many users would want subcommands to vary by case, and in 2.2 subcommand name matching was already case-insensitive.

private readonly HashSet<string> _names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private string _primaryCommandName;
internal CommandLineContext _context;
private IHelpTextGenerator _helpTextGenerator;
Expand Down Expand Up @@ -1003,7 +1003,6 @@ public void ShowRootCommandFullNameAndVersion()

internal bool MatchesName(string name)
{
// TODO: make this case-sensitive by default and add a parser setting
if (string.Equals(name, Name, StringComparison.OrdinalIgnoreCase))
{
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/CommandLineUtils/releasenotes.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project>
<PropertyGroup>
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.3.2'">
Bugs fixed:
* @jcaillon: Option for the case sensitivity of command names.
</PackageReleaseNotes>
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.3.1'">
Bugs fixed:
* Fix for InvalidOperationException thrown during help text generation on Mono
Expand Down
15 changes: 15 additions & 0 deletions test/CommandLineUtils.Tests/CommandLineApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public void CommandNameCanBeMatched()
Assert.True(called);
}

[Fact]
public void CommandsNamesAreCaseInsensitive()
{
var app = new CommandLineApplication();
var cmd = app.Command("TEST", c => {
c.OnExecute(() => 5);
});
cmd.AddName("TE");

Assert.Equal(5, app.Execute("test"));
Assert.Equal(5, app.Execute("TEST"));
Assert.Equal(5, app.Execute("te"));
Assert.Equal(5, app.Execute("TE"));
}

[Fact]
public void RemainingArgsArePassed()
{
Expand Down