Skip to content

Commit

Permalink
(chocolateyGH-468) Send Chocolatey Command Help to standard out not Err
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
secretGeek committed Jan 16, 2016
1 parent 3a2217f commit 4825062
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public abstract class ConfigurationOptionsSpecBase : TinySpec

protected Mock<IConsole> console = new Mock<IConsole>();
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<IConsole>(() => 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void show_help(OptionSet optionSet, Action helpMessage)
helpMessage.Invoke();
}

optionSet.WriteOptionDescriptions(Console.Error);
optionSet.WriteOptionDescriptions(Console.Out);
}
}
}
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure/adapters/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 9 additions & 0 deletions src/chocolatey/infrastructure/adapters/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public interface IConsole
/// <filterpriority>1</filterpriority>
TextWriter Error { get; }

/// <summary>
/// Gets the standard output stream.
/// </summary>
/// <returns>
/// A <see cref="T:System.IO.TextWriter" /> that represents the standard output stream.
/// </returns>
/// <filterpriority>1</filterpriority>
TextWriter Out { get; }

/// <summary>
/// Writes the specified string value to the standard output stream.
/// </summary>
Expand Down

0 comments on commit 4825062

Please sign in to comment.