Skip to content

Commit

Permalink
(GH-468) Log help to standard out, not standard error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
secretGeek authored and ferventcoder committed Jan 18, 2016
1 parent 15198fa commit 40001d0
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 40001d0

Please sign in to comment.