in Source/NuGetGallery.Operations/Infrastructure/CommandManager.cs [21:53]
public ICommand GetCommand(string commandName)
{
if (String.IsNullOrEmpty(commandName))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, commandName);
}
IEnumerable<ICommand> results = from command in _commands
where command.CommandAttribute.CommandName.StartsWith(commandName, StringComparison.OrdinalIgnoreCase) ||
(command.CommandAttribute.AltName ?? String.Empty).StartsWith(commandName, StringComparison.OrdinalIgnoreCase)
select command;
if (!results.Any())
{
throw new CommandLineException(TaskResources.UnknownCommandError, commandName);
}
var matchedCommand = results.First();
if (results.Skip(1).Any())
{
// Were there more than one results found?
matchedCommand = results.FirstOrDefault(c => c.CommandAttribute.CommandName.Equals(commandName, StringComparison.OrdinalIgnoreCase)
|| commandName.Equals(c.CommandAttribute.AltName, StringComparison.OrdinalIgnoreCase));
if (matchedCommand == null)
{
// No exact match was found and the result returned multiple prefixes.
throw new CommandLineException(String.Format(CultureInfo.CurrentCulture, TaskResources.AmbiguousCommand, commandName,
String.Join(" ", from c in results select c.CommandAttribute.CommandName)));
}
}
return matchedCommand;
}