Open kzu opened 1 month ago
I got a draft PR just to explore what the changes might be. Feel free to suggest alternatives. All existing tests pass fine, but I could not find unit tests specifically exercising the HelpProvider itself, to add a failing test and make it pass :). But the new output after the PR looks as I expected, without any formatting whatesoever:
USAGE:
trx [OPTIONS]
OPTIONS:
DEFAULT
-h, --help Prints help information
-p, --path Optional base directory for *.trx files
discovery. Defaults to current directory
-o, --output Include test output
-r, --recursive True Recursively search for *.trx files
--skipped True Include skipped tests
--no-exit-code Do not return a -1 exit code on test
failures
--version Show version information
--gh-comment True Report as GitHub PR comment
--gh-summary True Report as GitHub step summary
NO_COLOR
only prevents outputting colors, not ANSI control codes or CSI sequences related to style.
To automate output and get rid of ANSI sequences, you should disable ANSI completely using the console profile and add a switch in your application. NO_COLOR is not the way to go here.
You can also use a console recorder (https://spectreconsole.net/api/spectre.console/recorder/) to record the output.
Do you think there's an opportunity to provide something like this at least for the restricted use case of rendering text-only versions of help for the purposes of self-updating static docs for a tool?
Got a workaround for now in my app:
var app = new CommandApp();
// ...
app.Configure(config =>
{
if (Environment.GetEnvironmentVariables().Contains("NO_COLOR") &&
config.Settings.HelpProviderStyles?.Options is { } options)
options.DefaultValue = Style.Plain;
});
Hello @kzu,
FYI. there is a unit test demonstrating a completely unstyled help output, see:
That results in Style.Plain
being used throughout the help provider, eg:
I would probably recommend you follow this approach instead, which is very similar to yours, but would prevent any future issues with styling being added to other sections in the help writer output in future releases (nb. no plans to do so, just saying).
@FrankRay78 that didn't work. It seems it's being re-set by someone else. The default values are bold even though I set the help styles to null:
Thanks for testing @kzu, I'll bump this up my list of things to fix.
To Reproduce
Raw output:
Expected behavior Renders text only, with no bold or any other styles applied.
Screenshots Default values have bold style applied:
The importance of the issue is that it prevents having an automated way to self-document a CLI tool via the package readme, automatically updated after compile with up-to-date usage info, as shown in https://www.cazzulino.com/auto-doc-cli.html