From 40001d0b36df022bf5b11d54b0ca09d179e05cba Mon Sep 17 00:00:00 2001 From: secretGeek Date: Sat, 16 Jan 2016 10:53:13 +1000 Subject: [PATCH] (GH-468) Log help to standard out, not standard error Previously, help information was written out to stderr due to how NDesk OptionSet provides the help output. This causes commands such as the following to not page as expected: * `choco list -help | more` * `choco list -help | out-host -paging` Similarly `choco -help | out-file HelpDetails.txt` does not deliver all of the help output to the file. While there is a workaround of using `2>&1` (or `*>&1`) is burdensome for the very people who need help in the first place. Help information should instead be provided in stdout and not in stderr. This allows us to avoid these issues entirely. --- .../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. ///