Closed TAGC closed 2 years ago
From a quick inspection, it looks like the issue is with this bit of code, which determines the list of parameters that a CommandSchema
is constructed with: https://github.com/Tyrrrz/CliFx/blob/a9ef693dc153894e469f15cfad214cfa6857d94f/CliFx/Schema/CommandSchema.cs#L90-L93
This list of parameters is enumerated in that order by HelpConsoleFormatter
: https://github.com/Tyrrrz/CliFx/blob/a9ef693dc153894e469f15cfad214cfa6857d94f/CliFx/Formatting/HelpConsoleFormatter.cs#L74-L82
If I print out the properties of each type of command in the minimal repro code, I get the properties back in different orders:
public static async Task<int> Main()
{
var doesNotInheritFromBaseCommandProperties = typeof(DoesNotInheritFromBaseCommand).GetProperties();
var inheritFromBaseCommandProperties = typeof(InheritFromBaseCommand).GetProperties();
return 1;
}
doesNotInheritFromBaseCommandProperties
{System.Reflection.PropertyInfo[2]}
[0]: {Int64 Foo}
[1]: {Int64 Bar}
inheritFromBaseCommandProperties
{System.Reflection.PropertyInfo[2]}
[0]: {Int64 Bar}
[1]: {Int64 Foo}
Since ParameterSchema
has the Order
property associated with it, it might be possible to order the list of parameters by this property before passing it to the CommandSchema
constructor e.g.
var parameterSchemas = type.GetProperties()
.Select(ParameterSchema.TryResolve)
.Where(p => p is not null)
.OrderBy(p => p.Order)
.ToArray();
Hi, thanks for the report. Yes, the parameters need to be sorted by order in the help text renderer, it's a mistake that they aren't. PRs are welcome.
Version
2.0.6
Details
In some cases it's useful to have a base class implement
ICommand
and contain properties representing positional arguments that are common across multiple commands. For example, if you're writing a CLI app to manage customer orders, it might be useful to have something like:However, if you create a command that inherits from this base class and implements additional positional arguments (at order: 1, order: 2, etc.), these get listed out of order in the help description. For example, given:
When printing the help doc for this command, the following gets displayed:
It should instead be:
Steps to reproduce
To minimally reproduce, create a CLI app that implements these commands:
Compare the outputs when displaying the help doc for the "non-inherit" command (working as expected)...
Against the output for the "inherit" command: