From aab562be0340f3301a49e08822daee03d5d93d53 Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Mon, 12 Apr 2010 15:28:40 -0700 Subject: [PATCH] Adding support for "CommandHelp" attribute Also changed "Output" and "Input" to be TextReader instead of string Fix unit tests to work with new command descriptor semantics --HG-- branch : dev rename : src/Orchard/Commands/CommandManager.cs => src/Orchard/Commands/DefaultCommandManager.cs --- .../Commands/CommandHandlerTests.cs | 132 ++++++++++-------- .../Commands/CommandManagerTests.cs | 11 +- src/Orchard/Commands/Builtin/HelpCommand.cs | 24 ++++ src/Orchard/Commands/CommandContext.cs | 5 +- src/Orchard/Commands/CommandDescriptor.cs | 1 + .../CommandHandlerDescriptorBuilder.cs | 23 ++- src/Orchard/Commands/CommandHostAgent.cs | 11 +- src/Orchard/Commands/CommandModule.cs | 9 +- src/Orchard/Commands/CommandParameters.cs | 5 +- ...andManager.cs => DefaultCommandManager.cs} | 11 +- .../Commands/DefaultOrchardCommandHandler.cs | 22 ++- src/Orchard/Commands/ICommandManager.cs | 8 ++ .../Commands/OrchardCommandAttribute.cs | 8 ++ src/Orchard/Orchard.Framework.csproj | 4 +- src/Tools/Orchard/Host/CommandHost.cs | 2 + src/Tools/Orchard/OrchardParametersParser.cs | 5 +- 16 files changed, 188 insertions(+), 93 deletions(-) create mode 100644 src/Orchard/Commands/Builtin/HelpCommand.cs rename src/Orchard/Commands/{CommandManager.cs => DefaultCommandManager.cs} (86%) create mode 100644 src/Orchard/Commands/ICommandManager.cs diff --git a/src/Orchard.Tests/Commands/CommandHandlerTests.cs b/src/Orchard.Tests/Commands/CommandHandlerTests.cs index a08154cb3..b1e78dcb5 100644 --- a/src/Orchard.Tests/Commands/CommandHandlerTests.cs +++ b/src/Orchard.Tests/Commands/CommandHandlerTests.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.Collections.Specialized; +using System.IO; using NUnit.Framework; using Orchard.Commands; using System; +using System.Linq; namespace Orchard.Tests.Commands { [TestFixture] @@ -14,141 +16,152 @@ namespace Orchard.Tests.Commands { _handler = new StubCommandHandler(); } + private CommandContext CreateCommandContext(string commandName) { + return CreateCommandContext(commandName, new Dictionary(), new string[]{}); + } + + private CommandContext CreateCommandContext(string commandName, IDictionary switches) { + return CreateCommandContext(commandName, switches, new string[]{}); + } + + private CommandContext CreateCommandContext(string commandName, IDictionary switches, string[] args) { + var builder = new CommandHandlerDescriptorBuilder(); + + var descriptor = builder.Build(typeof(StubCommandHandler)); + + var commandDescriptor = descriptor.Commands.Single(d => string.Equals(d.Name, commandName, StringComparison.OrdinalIgnoreCase)); + + return new CommandContext { + Command = commandName, + Switches = switches, + CommandDescriptor = commandDescriptor, + Arguments = args, + Input = new StringReader(string.Empty), + Output = new StringWriter() + }; + } + [Test] public void TestFooCommand() { - CommandContext commandContext = new CommandContext { Command = "Foo" }; + var commandContext = CreateCommandContext("Foo"); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("Command Foo Executed")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("Command Foo Executed")); } [Test] public void TestNotExistingCommand() { - CommandContext commandContext = new CommandContext { Command = "NoSuchCommand" }; - Assert.Throws(() => _handler.Execute(commandContext)); + Assert.Throws(() => { + var commandContext = CreateCommandContext("NoSuchCommand"); + _handler.Execute(commandContext); + }); } [Test] public void TestCommandWithCustomAlias() { - CommandContext commandContext = new CommandContext { Command = "Bar" }; + var commandContext = CreateCommandContext("Bar"); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("Hello World!")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("Hello World!")); + } + + [Test] + public void TestHelpText() { + var commandContext = CreateCommandContext("Baz"); + Assert.That(commandContext.CommandDescriptor.HelpText, Is.EqualTo("Baz help")); + } + + [Test] + public void TestEmptyHelpText() { + var commandContext = CreateCommandContext("Foo"); + Assert.That(commandContext.CommandDescriptor.HelpText, Is.EqualTo(string.Empty)); } [Test] public void TestBooleanSwitchForCommand() { - CommandContext commandContext = new CommandContext { Command = "Baz", Switches = new Dictionary() }; - commandContext.Switches.Add("Verbose", "true"); + var commandContext = CreateCommandContext("Baz", new Dictionary {{"Verbose", "true"}}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("Command Baz Called : This was a test")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("Command Baz Called : This was a test")); } [Test] public void TestIntSwitchForCommand() { - CommandContext commandContext = new CommandContext { Command = "Baz", Switches = new Dictionary() }; - commandContext.Switches.Add("Level", "2"); + var commandContext = CreateCommandContext("Baz", new Dictionary {{"Level", "2"}}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("Command Baz Called : Entering Level 2")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("Command Baz Called : Entering Level 2")); } [Test] public void TestStringSwitchForCommand() { - CommandContext commandContext = new CommandContext { Command = "Baz", Switches = new Dictionary() }; - commandContext.Switches.Add("User", "OrchardUser"); + var commandContext = CreateCommandContext("Baz", new Dictionary {{"User", "OrchardUser"}}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("Command Baz Called : current user is OrchardUser")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("Command Baz Called : current user is OrchardUser")); } [Test] public void TestSwitchForCommandWithoutSupportForIt() { - CommandContext commandContext = new CommandContext { Command = "Foo", Switches = new Dictionary() }; - commandContext.Switches.Add("User", "OrchardUser"); + var switches = new Dictionary {{"User", "OrchardUser"}}; + var commandContext = CreateCommandContext("Foo", switches); Assert.Throws(() => _handler.Execute(commandContext)); } [Test] public void TestCommandThatDoesNotReturnAValue() { - CommandContext commandContext = new CommandContext { Command = "Log" }; + var commandContext = CreateCommandContext("Log"); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.Null); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("")); } [Test] public void TestNotExistingSwitch() { - CommandContext commandContext = new CommandContext { Command = "Foo", Switches = new Dictionary() }; - commandContext.Switches.Add("ThisSwitchDoesNotExist", "Insignificant"); + var switches = new Dictionary {{"ThisSwitchDoesNotExist", "Insignificant"}}; + var commandContext = CreateCommandContext("Foo", switches); Assert.Throws(() => _handler.Execute(commandContext)); } [Test] public void TestCommandArgumentsArePassedCorrectly() { - CommandContext commandContext = new CommandContext { - Command = "Concat", - Switches = new Dictionary(), - Arguments = new[] {"left to ", "right"} - }; + var commandContext = CreateCommandContext("Concat", new Dictionary(), new[] {"left to ", "right"}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("left to right")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("left to right")); } [Test] public void TestCommandArgumentsArePassedCorrectlyWithAParamsParameters() { - CommandContext commandContext = new CommandContext { - Command = "ConcatParams", - Switches = new Dictionary(), - Arguments = new[] {"left to ", "right"} - }; + var commandContext = CreateCommandContext("ConcatParams", new Dictionary(), new[] {"left to ", "right"}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("left to right")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("left to right")); } [Test] public void TestCommandArgumentsArePassedCorrectlyWithAParamsParameterAndNoArguments() { - CommandContext commandContext = new CommandContext { - Command = "ConcatParams", - Switches = new Dictionary() - }; + var commandContext = CreateCommandContext("ConcatParams", new Dictionary()); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("")); } - [Test] public void TestCommandArgumentsArePassedCorrectlyWithNormalParametersAndAParamsParameters() { - CommandContext commandContext = new CommandContext { - Command = "ConcatAllParams", - Switches = new Dictionary(), - Arguments = new[] { "left-", "center-", "right" } - }; + var commandContext = CreateCommandContext("ConcatAllParams", + new Dictionary(), + new[] { "left-", "center-", "right"}); _handler.Execute(commandContext); - Assert.That(commandContext.Output, Is.EqualTo("left-center-right")); + Assert.That(commandContext.Output.ToString(), Is.EqualTo("left-center-right")); } [Test] public void TestCommandParamsMismatchWithoutParamsNotEnoughArguments() { - CommandContext commandContext = new CommandContext { - Command = "Concat", - Switches = new Dictionary(), - Arguments = new[] { "left to "} - }; + var commandContext = CreateCommandContext("Concat", new Dictionary(), new[] { "left to " }); Assert.Throws(() => _handler.Execute(commandContext)); } [Test] public void TestCommandParamsMismatchWithoutParamsTooManyArguments() { - CommandContext commandContext = new CommandContext { - Command = "Foo", - Switches = new Dictionary(), - Arguments = new[] { "left to " } - }; + var commandContext = CreateCommandContext("Foo", new Dictionary(), new[] { "left to " }); Assert.Throws(() => _handler.Execute(commandContext)); } [Test] public void TestCommandParamsMismatchWithParamsButNotEnoughArguments() { - CommandContext commandContext = new CommandContext { - Command = "ConcatAllParams", - Switches = new Dictionary(), - }; + var commandContext = CreateCommandContext("ConcatAllParams", new Dictionary()); Assert.Throws(() => _handler.Execute(commandContext)); } } @@ -173,6 +186,7 @@ namespace Orchard.Tests.Commands { } [OrchardSwitches("Verbose, Level, User")] + [CommandHelp("Baz help")] public string Baz() { string trace = "Command Baz Called"; diff --git a/src/Orchard.Tests/Commands/CommandManagerTests.cs b/src/Orchard.Tests/Commands/CommandManagerTests.cs index 43b5bfcb8..27ad6666e 100644 --- a/src/Orchard.Tests/Commands/CommandManagerTests.cs +++ b/src/Orchard.Tests/Commands/CommandManagerTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using Autofac; @@ -14,7 +15,7 @@ namespace Orchard.Tests.Commands { [SetUp] public void Init() { var builder = new ContainerBuilder(); - builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterModule(new CommandModule()); var container = builder.Build(); @@ -24,16 +25,16 @@ namespace Orchard.Tests.Commands { [Test] public void ManagerCanRunACommand() { - var context = new CommandParameters { Arguments = new string[] { "FooBar" } }; + var context = new CommandParameters { Arguments = new string[] { "FooBar" }, Output = new StringWriter()}; _manager.Execute(context); - Assert.That(context.Output, Is.EqualTo("success!")); + Assert.That(context.Output.ToString(), Is.EqualTo("success!")); } [Test] public void ManagerCanRunACompositeCommand() { - var context = new CommandParameters { Arguments = ("Foo Bar Bleah").Split(' ') }; + var context = new CommandParameters { Arguments = ("Foo Bar Bleah").Split(' '), Output = new StringWriter() }; _manager.Execute(context); - Assert.That(context.Output, Is.EqualTo("Bleah")); + Assert.That(context.Output.ToString(), Is.EqualTo("Bleah")); } public class MyCommand : DefaultOrchardCommandHandler { diff --git a/src/Orchard/Commands/Builtin/HelpCommand.cs b/src/Orchard/Commands/Builtin/HelpCommand.cs new file mode 100644 index 000000000..1a152102e --- /dev/null +++ b/src/Orchard/Commands/Builtin/HelpCommand.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Autofac.Features.Metadata; + +namespace Orchard.Commands.Builtin { + public class HelpCommand : DefaultOrchardCommandHandler { + private readonly ICommandManager _commandManager; + + public HelpCommand(ICommandManager commandManager) { + _commandManager = commandManager; + } + + [OrchardCommand("help commands")] + [CommandHelp("List all available commands")] + public void Commands() { + var descriptors = _commandManager.GetCommandDescriptors(); + foreach (var descriptor in descriptors) { + var helpText = string.IsNullOrEmpty(descriptor.HelpText) ? T("[no help text]") : T(descriptor.HelpText); + Context.Output.WriteLine("{0}: {1}", descriptor.Name, helpText); + } + } + } +} diff --git a/src/Orchard/Commands/CommandContext.cs b/src/Orchard/Commands/CommandContext.cs index e04d8ffd9..8f1ed039f 100644 --- a/src/Orchard/Commands/CommandContext.cs +++ b/src/Orchard/Commands/CommandContext.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.IO; namespace Orchard.Commands { public class CommandContext { - public string Input { get; set; } - public string Output { get; set; } + public TextReader Input { get; set; } + public TextWriter Output { get; set; } public string Command { get; set; } public IEnumerable Arguments { get; set; } public IDictionary Switches { get; set; } diff --git a/src/Orchard/Commands/CommandDescriptor.cs b/src/Orchard/Commands/CommandDescriptor.cs index 1d0071a53..22a52ee6e 100644 --- a/src/Orchard/Commands/CommandDescriptor.cs +++ b/src/Orchard/Commands/CommandDescriptor.cs @@ -5,5 +5,6 @@ namespace Orchard.Commands { public class CommandDescriptor { public string Name { get; set; } public MethodInfo MethodInfo { get; set; } + public string HelpText { get; set; } } } \ No newline at end of file diff --git a/src/Orchard/Commands/CommandHandlerDescriptorBuilder.cs b/src/Orchard/Commands/CommandHandlerDescriptorBuilder.cs index 1337c94b8..3d82cc0b0 100644 --- a/src/Orchard/Commands/CommandHandlerDescriptorBuilder.cs +++ b/src/Orchard/Commands/CommandHandlerDescriptorBuilder.cs @@ -2,22 +2,35 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; namespace Orchard.Commands { public class CommandHandlerDescriptorBuilder { public CommandHandlerDescriptor Build(Type type) { - var methods = CollectMethods(type); - return new CommandHandlerDescriptor { Commands = methods }; + return new CommandHandlerDescriptor { Commands = CollectMethods(type) }; } private IEnumerable CollectMethods(Type type) { foreach (var methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { - var name = GetCommandName(methodInfo); - yield return new CommandDescriptor { Name = name, MethodInfo = methodInfo }; + yield return BuildMethod(methodInfo); } } + private CommandDescriptor BuildMethod(MethodInfo methodInfo) { + return new CommandDescriptor { + Name = GetCommandName(methodInfo), + MethodInfo = methodInfo, + HelpText = GetCommandHelpText(methodInfo) + }; + } + + private string GetCommandHelpText(MethodInfo methodInfo) { + var attributes = methodInfo.GetCustomAttributes(typeof(CommandHelpAttribute), false/*inherit*/); + if (attributes != null && attributes.Any()) { + return attributes.Cast().Single().HelpText; + } + return string.Empty; + } + private string GetCommandName(MethodInfo methodInfo) { var attributes = methodInfo.GetCustomAttributes(typeof(OrchardCommandAttribute), false/*inherit*/); if (attributes != null && attributes.Any()) { diff --git a/src/Orchard/Commands/CommandHostAgent.cs b/src/Orchard/Commands/CommandHostAgent.cs index 7342bfb2c..94c1da53b 100644 --- a/src/Orchard/Commands/CommandHostAgent.cs +++ b/src/Orchard/Commands/CommandHostAgent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.IO; using System.Linq; using System.Text; using System.Web.Mvc; @@ -15,7 +16,7 @@ namespace Orchard.Commands { /// executing a single command. /// public class CommandHostAgent { - public void RunSingleCommand(string tenant, string[] args, Dictionary switches) { + public void RunSingleCommand(TextReader input, TextWriter output, string tenant, string[] args, Dictionary switches) { try { var hostContainer = OrchardStarter.CreateHostContainer(MvcSingletons); var host = hostContainer.Resolve(); @@ -28,7 +29,13 @@ namespace Orchard.Commands { // Disptach command execution to ICommandManager using (var env = host.CreateStandaloneEnvironment(tenantSettings)) { - env.Resolve().Execute(new CommandParameters {Arguments = args, Switches = switches}); + var parameters = new CommandParameters { + Arguments = args, + Switches = switches, + Input = input, + Output = output + }; + env.Resolve().Execute(parameters); } } catch (Exception e) { diff --git a/src/Orchard/Commands/CommandModule.cs b/src/Orchard/Commands/CommandModule.cs index c857232b5..442111f62 100644 --- a/src/Orchard/Commands/CommandModule.cs +++ b/src/Orchard/Commands/CommandModule.cs @@ -12,9 +12,12 @@ namespace Orchard.Commands { if (!registration.Services.Contains(new TypedService(typeof(ICommandHandler)))) return; - var builder = new CommandHandlerDescriptorBuilder(); - var descriptor = builder.Build(registration.Activator.LimitType); - registration.Metadata.Add(typeof(CommandHandlerDescriptor).FullName, descriptor); + // Workaround autofac integration: module registration is currently run twice... + if (!registration.Metadata.ContainsKey(typeof(CommandHandlerDescriptor).FullName)) { + var builder = new CommandHandlerDescriptorBuilder(); + var descriptor = builder.Build(registration.Activator.LimitType); + registration.Metadata.Add(typeof (CommandHandlerDescriptor).FullName, descriptor); + } } } } diff --git a/src/Orchard/Commands/CommandParameters.cs b/src/Orchard/Commands/CommandParameters.cs index 3d685c318..6851549ab 100644 --- a/src/Orchard/Commands/CommandParameters.cs +++ b/src/Orchard/Commands/CommandParameters.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -8,7 +9,7 @@ namespace Orchard.Commands { public IEnumerable Arguments { get; set; } public IDictionary Switches { get; set; } - public string Input { get; set; } - public string Output { get; set; } + public TextReader Input { get; set; } + public TextWriter Output { get; set; } } } diff --git a/src/Orchard/Commands/CommandManager.cs b/src/Orchard/Commands/DefaultCommandManager.cs similarity index 86% rename from src/Orchard/Commands/CommandManager.cs rename to src/Orchard/Commands/DefaultCommandManager.cs index a00737d58..43155bc80 100644 --- a/src/Orchard/Commands/CommandManager.cs +++ b/src/Orchard/Commands/DefaultCommandManager.cs @@ -5,14 +5,10 @@ using System.Text; using Autofac.Features.Metadata; namespace Orchard.Commands { - public interface ICommandManager : IDependency { - void Execute(CommandParameters parameters); - } - - public class CommandManager : ICommandManager { + public class DefaultCommandManager : ICommandManager { private readonly IEnumerable>> _handlers; - public CommandManager(IEnumerable>> handlers) { + public DefaultCommandManager(IEnumerable>> handlers) { _handlers = handlers; } @@ -32,6 +28,9 @@ namespace Orchard.Commands { } } + public IEnumerable GetCommandDescriptors() { + return _handlers.SelectMany(h => GetDescriptor(h.Metadata).Commands); + } private class Match { public CommandContext Context { get; set; } diff --git a/src/Orchard/Commands/DefaultOrchardCommandHandler.cs b/src/Orchard/Commands/DefaultOrchardCommandHandler.cs index ec853898f..f593fd6b8 100644 --- a/src/Orchard/Commands/DefaultOrchardCommandHandler.cs +++ b/src/Orchard/Commands/DefaultOrchardCommandHandler.cs @@ -12,11 +12,17 @@ namespace Orchard.Commands { } public Localizer T { get; set; } + public CommandContext Context { get; set; } #region Implementation of ICommandHandler public void Execute(CommandContext context) { - if (context.Switches != null && context.Switches.Count > 0) { + SetSwitchValues(context); + Invoke(context); + } + + private void SetSwitchValues(CommandContext context) { + if (context.Switches != null && context.Switches.Any()) { foreach (var commandSwitch in context.Switches.Keys) { PropertyInfo propertyInfo = GetType().GetProperty(commandSwitch); if (propertyInfo == null) { @@ -45,17 +51,19 @@ namespace Orchard.Commands { } } } - - InvokeCommand(context); } - private void InvokeCommand(CommandContext context) { + private void Invoke(CommandContext context) { CheckMethodForSwitches(context.CommandDescriptor.MethodInfo, context.Switches); - object[] invokeParameters = GetInvokeParametersForMethod(context.CommandDescriptor.MethodInfo, context.Arguments.ToArray() ?? new string[] { }); + object[] invokeParameters = GetInvokeParametersForMethod(context.CommandDescriptor.MethodInfo, (context.Arguments ?? Enumerable.Empty()).ToArray()); if (invokeParameters == null) { - throw new ArgumentException(T("Command arguments don't match").ToString()); + throw new InvalidOperationException(T("Command arguments don't match").ToString()); } - context.Output = (string)context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters); + + this.Context = context; + var result = context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters); + if (result is string) + context.Output.Write(result); } private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, IList arguments) { diff --git a/src/Orchard/Commands/ICommandManager.cs b/src/Orchard/Commands/ICommandManager.cs new file mode 100644 index 000000000..4852b30c9 --- /dev/null +++ b/src/Orchard/Commands/ICommandManager.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace Orchard.Commands { + public interface ICommandManager : IDependency { + void Execute(CommandParameters parameters); + IEnumerable GetCommandDescriptors(); + } +} \ No newline at end of file diff --git a/src/Orchard/Commands/OrchardCommandAttribute.cs b/src/Orchard/Commands/OrchardCommandAttribute.cs index b72330530..a06ae6658 100644 --- a/src/Orchard/Commands/OrchardCommandAttribute.cs +++ b/src/Orchard/Commands/OrchardCommandAttribute.cs @@ -12,6 +12,14 @@ namespace Orchard.Commands { public string Command { get { return _commandAlias; } } + } + [AttributeUsage(AttributeTargets.Method)] + public class CommandHelpAttribute : Attribute { + public CommandHelpAttribute(string text) { + this.HelpText = text; + } + + public string HelpText { get; set; } } } diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 36d73bdf6..67e763a87 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -142,8 +142,10 @@ - + + + diff --git a/src/Tools/Orchard/Host/CommandHost.cs b/src/Tools/Orchard/Host/CommandHost.cs index 6eabadbf0..3a5d01ea0 100644 --- a/src/Tools/Orchard/Host/CommandHost.cs +++ b/src/Tools/Orchard/Host/CommandHost.cs @@ -22,6 +22,8 @@ namespace Orchard.Host { public void RunCommand(OrchardParameters args) { var agent = Activator.CreateInstance("Orchard.Framework", "Orchard.Commands.CommandHostAgent").Unwrap(); agent.GetType().GetMethod("RunSingleCommand").Invoke(agent, new object[] { + Console.In, + Console.Out, args.Tenant, args.Arguments.ToArray(), args.Switches}); diff --git a/src/Tools/Orchard/OrchardParametersParser.cs b/src/Tools/Orchard/OrchardParametersParser.cs index 5008b7ef2..587149791 100644 --- a/src/Tools/Orchard/OrchardParametersParser.cs +++ b/src/Tools/Orchard/OrchardParametersParser.cs @@ -20,7 +20,10 @@ namespace Orchard { case "v": case "verbose": - result.Verbose = bool.Parse(sw.Value); + bool verbose; + if (!bool.TryParse(sw.Value, out verbose)) + verbose = true; + result.Verbose = verbose; break; case "vp":