From 48250627476629abb1b30a3ccea44f94dbed326a Mon Sep 17 00:00:00 2001 From: secretGeek Date: Sat, 16 Jan 2016 10:53:13 +1000 Subject: [PATCH] (GH-468) Send Chocolatey Command Help to standard out not Err Commands such as: choco list -help | more choco list -help | out-host -paging ...did not page as expected. Similarly: choco -help | out-file HelpDetails.txt did not deliver all of the help output to the file. (The workaround of using 2>&1 (or *>&1) is burdensome for the very people who need help in the first place.) So, in line with normal use of NDesk OptionSet, the option descriptions are now written to Console.Out not Console.Error. --- .../configuration/ConfigurationOptionsSpec.cs | 6 ++++-- .../configuration/ConfigurationOptions.cs | 2 +- src/chocolatey/infrastructure/adapters/Console.cs | 2 ++ src/chocolatey/infrastructure/adapters/IConsole.cs | 9 +++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs index 99352ae65e..db1aa1e9ae 100644 --- a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs +++ b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs @@ -39,13 +39,15 @@ public abstract class ConfigurationOptionsSpecBase : TinySpec protected Mock console = new Mock(); protected static StringBuilder helpMessageContents = new StringBuilder(); - protected TextWriter writer = new StringWriter(helpMessageContents); + protected TextWriter errorWriter = new StringWriter(helpMessageContents); + protected TextWriter outputWriter = new StringWriter(helpMessageContents); public override void Context() { ConfigurationOptions.initialize_with(new Lazy(() => console.Object)); ConfigurationOptions.reset_options(); - console.Setup((c) => c.Error).Returns(writer); + console.Setup((c) => c.Error).Returns(errorWriter); + console.Setup((c) => c.Out).Returns(outputWriter); } protected Action because; diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs index aa76a485dc..e55cd48073 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs @@ -134,7 +134,7 @@ private static void show_help(OptionSet optionSet, Action helpMessage) helpMessage.Invoke(); } - optionSet.WriteOptionDescriptions(Console.Error); + optionSet.WriteOptionDescriptions(Console.Out); } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure/adapters/Console.cs b/src/chocolatey/infrastructure/adapters/Console.cs index 9e6a0b4721..6a1ceeeafd 100644 --- a/src/chocolatey/infrastructure/adapters/Console.cs +++ b/src/chocolatey/infrastructure/adapters/Console.cs @@ -42,6 +42,8 @@ public System.ConsoleKeyInfo ReadKey(int timeoutMilliseconds) public TextWriter Error { get { return System.Console.Error; } } + public TextWriter Out { get { return System.Console.Out; } } + public void Write(object value) { System.Console.Write(value.to_string()); diff --git a/src/chocolatey/infrastructure/adapters/IConsole.cs b/src/chocolatey/infrastructure/adapters/IConsole.cs index 2e298645c6..a43d493c69 100644 --- a/src/chocolatey/infrastructure/adapters/IConsole.cs +++ b/src/chocolatey/infrastructure/adapters/IConsole.cs @@ -54,6 +54,15 @@ public interface IConsole /// 1 TextWriter Error { get; } + /// + /// Gets the standard output stream. + /// + /// + /// A that represents the standard output stream. + /// + /// 1 + TextWriter Out { get; } + /// /// Writes the specified string value to the standard output stream. ///