Skip to content

Commit 09a627d

Browse files
authored
Merge pull request #11 from georgevella/feature/shortname_fix
Feature/shortname fix
2 parents 5e8b50f + 80b3ca5 commit 09a627d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

GoCommando.Tests/TestCommand.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,26 @@ public void CanCorrectlyHandleDifferentAlternativeSwitchFormatsFoundInOneSingleT
2525
Assert.That(bimseInstance.Switch, Is.EqualTo("value2"));
2626
}
2727

28+
[TestCase("-s:value2")]
29+
[TestCase("-s=value2")]
30+
[TestCase(@"-s""value2""")]
31+
public void CanCorrectlyHandleDifferentAlternativeSwitchFormatsFoundInOneSingleTokenOnly_Shortname(string switchText)
32+
{
33+
var settings = new Settings();
34+
var invoker = new CommandInvoker("bimse", settings, new Bimse());
35+
var arguments = Go.Parse(new[] { switchText }, settings);
36+
37+
invoker.Invoke(arguments.Switches, EnvironmentSettings.Empty);
38+
39+
var bimseInstance = (Bimse)invoker.CommandInstance;
40+
41+
Assert.That(bimseInstance.Switch, Is.EqualTo("value2"));
42+
}
43+
2844
[Command("bimse")]
2945
class Bimse : ICommand
3046
{
31-
[Parameter("switch")]
47+
[Parameter("switch", shortName: "s")]
3248
public string Switch { get; set; }
3349

3450
public void Run()

GoCommando/Internals/CommandInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static bool CanBeResolvedFromEnvironmentSettings(EnvironmentSettings environment
265265

266266
static bool CanBeResolvedFromSwitches(IEnumerable<Switch> switches, Parameter p)
267267
{
268-
return switches.Any(s => s.Key == p.Name);
268+
return switches.Any(s => p.MatchesKey(s.Key));
269269
}
270270
}
271271
}

0 commit comments

Comments
 (0)