Display error when 0 or more than 2 commands match

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-04-28 22:39:08 -07:00
parent 7788ad20c8
commit 6c75b28a81

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac.Features.Metadata;
namespace Orchard.Commands {
@@ -19,11 +18,17 @@ namespace Orchard.Commands {
var match = matches.Single();
match.CommandHandlerFactory().Execute(match.Context);
}
else if (matches.Any()) {
// too many
}
else {
// none
var commandMatch = string.Join(" ", parameters.Arguments.ToArray());
var commandList = string.Join(",", GetCommandDescriptors().Select(d => d.Name).ToArray());
if (matches.Any()) {
throw new OrchardException(string.Format("Multiple commands found matching arguments \"{0}\". Commands available: {1}.",
commandMatch, commandList));
}
else {
throw new OrchardException(string.Format("No command found matching arguments \"{0}\". Commands available: {1}.",
commandMatch, commandList));
}
}
}
@@ -32,9 +37,10 @@ namespace Orchard.Commands {
}
private IEnumerable<Match> MatchCommands(CommandParameters parameters) {
// Command names are matched with as many arguments as possible, in decreasing order
foreach (var argCount in Enumerable.Range(1, parameters.Arguments.Count()).Reverse()) {
int count = argCount;
var matches = _handlers.SelectMany(h => MatchCommands(parameters, count, GetDescriptor(h.Metadata), h.Value));
var matches = _handlers.SelectMany(h => MatchCommands(parameters, count, GetDescriptor(h.Metadata), h.Value)).ToList();
if (matches.Any())
return matches;
}