Honor user defined order of commands, subcommands and options#1215
Honor user defined order of commands, subcommands and options#1215gabrielmaldi wants to merge 1 commit intodotnet:mainfrom
Conversation
781746e to
9eb1129
Compare
9eb1129 to
fd49a4e
Compare
|
The convention in most command line help (at least for options) is for the short-form aliases to precede the long-form aliases, so the current ordering is deliberate. There's been discussion though about making help easier to customize, in a way that would accommodate the desire to reorder the aliases. @Keboo @adamhewitt627 ...thoughts? |
|
I agree, I think this is another case that needs to be handled with making configuring the help output |
|
This is how I'm handling it right now: new CommandLineBuilder(rootCommand)
.UseHelpBuilder(context => new HelpBuilderEx(context.Console))
.UseDefaults()
.Build()
.Invoke(args);public class HelpBuilderEx : HelpBuilder
{
public HelpBuilderEx(
IConsole console,
int? columnGutter = null,
int? indentationSize = null,
int? maxWidth = null)
: base(console, columnGutter, indentationSize, maxWidth)
{
}
protected override string DefaultValueHint(IArgument argument, bool isSingleArgument)
{
if (argument is IArgumentEx argumentEx && argumentEx.DefaultValueHintFactory != null)
{
var surrogate = new Argument(argument.Name);
surrogate.SetDefaultValueFactory(argumentEx.DefaultValueHintFactory);
argument = surrogate;
}
return base.DefaultValueHint(argument, isSingleArgument);
}
}Which of course is less than ideal. I agree that it would be better to make private IEnumerable<HelpItem> GetOptionHelpItems(IIdentifierSymbol symbol)
{
var rawAliases = symbol
.Aliases
.Select(r => r.SplitPrefix())
.OrderBy(r => r.prefix, StringComparer.OrdinalIgnoreCase)
.GroupBy(t => t.alias)
.Select(t => t.First())
.Select(t => $"{t.prefix}{t.alias}");And extract this bit ( |
|
Is this needed after #2073? CliCommand and CliOption now have both command-line-api/src/System.CommandLine/Help/HelpBuilder.Default.cs Lines 90 to 98 in e26fc94 Even if you still need to preserve the order of aliases, you cannot do that just by making HelpBuilder sort the aliases, because AliasSet stores them to |
Currently,
HelpBuildersorts help items, which results in the following behavior:Example 1
Example 2
User defined order should be respected; otherwise, the aliases (
hc) can be shown before the main command (health-checks). Also, multiple commands can result in odd ordering:mini-profiler, mpandhc, health-checks(main/alias, alias/main; see Example 2).For completeness: