mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Display error when 0 or more than 2 commands match
--HG-- branch : dev
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user