Skip to content

Usage section shows Argument.Name rather than Argument.HelpName #2004

Open
@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

In the help output, the Usage section shows Argument.Name, but the Arguments section shows Argument.HelpName. I think this is inconsistent and they should both use Argument.HelpName if set, so that Argument.Name would be culture-invariant and usable for System.CommandLine.NamingConventionBinder. #1891 (comment)

Demo

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
  </ItemGroup>

</Project>
using System.CommandLine;
using System.IO;

var command = new RootCommand()
{
    new Argument<FileInfo>(name: "inputfile")
    {
        HelpName = "inputfile.log",
    },
};

return await command.InvokeAsync(args);
$ dotnet run
Required argument missing for command: 'ArgumentHelpDemo'.

Description:

Usage:
  ArgumentHelpDemo <inputfile> [options]

Arguments:
  <inputfile.log>

Options:
  --version       Show version information
  -?, -h, --help  Show help and usage information

Current implementation

Usage section:

if (isOptional)
{
sb.Append($"[<{argument.Name}>{arityIndicator}");
(end ??= new Stack<char>()).Push(']');
}
else
{
sb.Append($"<{argument.Name}>{arityIndicator}");
}

Arguments section:

var arg = argument;
var helpName = arg?.HelpName ?? string.Empty;
if (!string.IsNullOrEmpty(helpName))
{
firstColumn = helpName!;
}
else if (completions.Length > 0)
{
firstColumn = string.Join("|", completions);
}
else
{
firstColumn = argument.Name;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions