command-line-api
command-line-api copied to clipboard
Help output for commands has lots of trailing newlines
It's pretty similar for all of the commands, but some only have 3ish newlines, while others have 5ish. Can we reduce this overhead?
transferring to command-line-api, it's a default implementation. Test case below:
var argument = new Argument<string>
{
Name = "the-arg",
};
var option = new Option<string>("the-option");
var command = new Command("outer", "outer command help")
{
new Command("inner", $"inner command help")
{
argument,
option
}
};
HelpBuilder helpBuilder = GetHelpBuilder(LargeMaxWidth);
helpBuilder.Write(command.Children.OfType<Command>().Single(), _console);
Output below:
Description:
inner command help
Usage:
outer inner <the-arg> <inner-other-arg-no-default> [options]
Arguments:
<the-arg>
<inner-other-arg-no-default>
Options:
the-option <the-option>
The extra new lines in order of appearance:
- https://github.com/dotnet/command-line-api/blob/372d408431a3c0001cbe9e8e247a8e1561dc2e89/src/System.CommandLine/Help/HelpBuilder.Default.cs#L246
- https://github.com/dotnet/command-line-api/blob/372d408431a3c0001cbe9e8e247a8e1561dc2e89/src/System.CommandLine/Help/HelpBuilder.cs#L71
- https://github.com/dotnet/command-line-api/blob/372d408431a3c0001cbe9e8e247a8e1561dc2e89/src/System.CommandLine/Help/HelpBuilder.cs#L75
Based on some testing, I believe the following two empty lines are not required:
https://github.com/dotnet/command-line-api/blob/8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb/src/System.CommandLine/Help/HelpBuilder.Default.cs#L241
https://github.com/dotnet/command-line-api/blob/8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb/src/System.CommandLine/Help/HelpBuilder.cs#L61
@jonsequitur Do you think this could be checked out? It seems this library is now used for the main dotnet
CLI too and the affects of this are visible when using that too:
e.g.
~\source\windoriel on main [?] via .NET v7.0.302 🎯 net7.0-windows
🕙 [ 11:43:03 AM ] ❯ dotnet run -h
Description:
.NET Run Command
Usage:
dotnet run [<applicationArguments>...] [options]
Arguments:
<applicationArguments> Arguments passed to the application that is being run. []
Options:
-c, --configuration <CONFIGURATION> The configuration to run for. The default for most projects is 'Debug'.
-f, --framework <FRAMEWORK> The target framework to run for. The target framework must also be specified in the project
file.
-r, --runtime <RUNTIME_IDENTIFIER> The target runtime to run for.
--project <project> The path to the project file to run (defaults to the current directory if there is only one
project).
-p, --property <property> Properties to be passed to MSBuild.
-lp, --launch-profile <launch-profile> The name of the launch profile (if any) to use when launching the application.
--no-launch-profile Do not attempt to use launchSettings.json to configure the application.
--no-build Do not build the project before running. Implies --no-restore.
--interactive Allows the command to stop and wait for user input or action (for example to complete
authentication).
--no-restore Do not restore the project before building.
--sc, --self-contained Publish the .NET runtime with your application so the runtime doesn't need to be installed
on the target machine.
The default is 'true' if a runtime identifier is specified.
--no-self-contained Publish your application as a framework dependent application. A compatible .NET runtime
must be installed on the target machine to run your application.
-v, --verbosity <LEVEL> Set the MSBuild verbosity level. Allowed values are q[uiet], m[inimal], n[ormal],
d[etailed], and diag[nostic].
-a, --arch <arch> The target architecture.
--os <os> The target operating system.
-?, -h, --help Show command line help.
~\source\windoriel on main [?] via .NET v7.0.302 🎯 net7.0-windows
🕙 [ 11:43:04 AM ] ❯ dotnet build -h
Description:
.NET Builder
Usage:
dotnet build [<PROJECT | SOLUTION>...] [options]
Arguments:
<PROJECT | SOLUTION> The project or solution file to operate on. If a file is not specified, the command will search the current
directory for one.
Options:
--ucr, --use-current-runtime Use current runtime as the target runtime.
-f, --framework <FRAMEWORK> The target framework to build for. The target framework must also be specified in the project
file.
-c, --configuration <CONFIGURATION> The configuration to use for building the project. The default for most projects is 'Debug'.
-r, --runtime <RUNTIME_IDENTIFIER> The target runtime to build for.
--version-suffix <VERSION_SUFFIX> Set the value of the $(VersionSuffix) property to use when building the project.
--no-restore Do not restore the project before building.
--interactive Allows the command to stop and wait for user input or action (for example to complete
authentication).
-v, --verbosity <LEVEL> Set the MSBuild verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed],
and diag[nostic].
--debug
-o, --output <OUTPUT_DIR> The output directory to place built artifacts in.
--no-incremental Do not use incremental building.
--no-dependencies Do not build project-to-project references and only build the specified project.
--nologo Do not display the startup banner or the copyright message.
--sc, --self-contained Publish the .NET runtime with your application so the runtime doesn't need to be installed on
the target machine.
The default is 'true' if a runtime identifier is specified.
--no-self-contained Publish your application as a framework dependent application. A compatible .NET runtime must
be installed on the target machine to run your application.
-a, --arch <arch> The target architecture.
--os <os> The target operating system.
--disable-build-servers Force the command to ignore any persistent build servers.
-?, -h, --help Show command line help.
~\source\windoriel on main [?] via .NET v7.0.302 🎯 net7.0-windows
🕙 [ 11:43:09 AM ] ❯
Thanks heaps Fotis