Skip to content

Commit

Permalink
Merge pull request #11 from georgevella/feature/shortname_fix
Browse files Browse the repository at this point in the history
Feature/shortname fix
  • Loading branch information
mookid8000 authored Nov 30, 2016
2 parents 5e8b50f + 80b3ca5 commit 09a627d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion GoCommando.Tests/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@ public void CanCorrectlyHandleDifferentAlternativeSwitchFormatsFoundInOneSingleT
Assert.That(bimseInstance.Switch, Is.EqualTo("value2"));
}

[TestCase("-s:value2")]
[TestCase("-s=value2")]
[TestCase(@"-s""value2""")]
public void CanCorrectlyHandleDifferentAlternativeSwitchFormatsFoundInOneSingleTokenOnly_Shortname(string switchText)
{
var settings = new Settings();
var invoker = new CommandInvoker("bimse", settings, new Bimse());
var arguments = Go.Parse(new[] { switchText }, settings);

invoker.Invoke(arguments.Switches, EnvironmentSettings.Empty);

var bimseInstance = (Bimse)invoker.CommandInstance;

Assert.That(bimseInstance.Switch, Is.EqualTo("value2"));
}

[Command("bimse")]
class Bimse : ICommand
{
[Parameter("switch")]
[Parameter("switch", shortName: "s")]
public string Switch { get; set; }

public void Run()
Expand Down
2 changes: 1 addition & 1 deletion GoCommando/Internals/CommandInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static bool CanBeResolvedFromEnvironmentSettings(EnvironmentSettings environment

static bool CanBeResolvedFromSwitches(IEnumerable<Switch> switches, Parameter p)
{
return switches.Any(s => s.Key == p.Name);
return switches.Any(s => p.MatchesKey(s.Key));
}
}
}

0 comments on commit 09a627d

Please sign in to comment.