ookii.commandline icon indicating copy to clipboard operation
ookii.commandline copied to clipboard

[Feature Request] Add a new sort mode for argument descriptions based on the order of properties in the class

Open DarkRRb opened this issue 5 months ago • 1 comments

Problem Description

When generating help text via --help, the ArgumentDescriptionListOrder property only supports sorting by usage syntax or alphabetical order. There is no option to sort arguments based on their declaration order in the class. For example:

[GeneratedParser]
public partial class Argument {
    [CommandLineArgument("bb", ShortName = 'b')] // Declared first
    public required string B { get; init; }

    [CommandLineArgument("cc", ShortName = 'c')] // Declared second
    public required string C { get; init; }

    [CommandLineArgument("aa", ShortName = 'a')] // Declared third
    public required string A { get; init; }
}

Current output sorts alphabetically by argument name (aa, bb, cc), ignoring the property declaration order.

Requested Feature

Add a new DescriptionListSortMode option (e.g., DeclarationOrder) to display arguments in the same order as they appear in the class definition.

var options = new ParseOptions { 
    IsPosix = true,
    UsageWriter = { ArgumentDescriptionListOrder = DescriptionListSortMode.DeclarationOrder }
};
Argument.Parse(args, options);

Help output should preserve declaration order:

text
Usage: Demo --bb <string> --cc <string> --aa <string> [--help] [--version]

    -b, --bb <string>
            I hope it appears first

    -c, --cc <string>
            I want it to appear in the second

    -a, --aa <string>
            I hope it appears in the third

DarkRRb avatar Jul 29 '25 16:07 DarkRRb