spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
9.19k stars 474 forks source link

Commands section of help message does not list anything #908

Closed Fed03 closed 8 months ago

Fed03 commented 2 years ago

Information

Describe the bug When calling the the CommandApp via CLI without a default Command, the commands section of the displayed help message does not list anything.

To Reproduce Just configure a CommandApp without a default command and with a bunch of standard commands, i.e.

c.AddCommand<SendNormalizedRecordToLime>("send");
c.AddCommand<NormalizeLimeCsvCommand>("normalize");

Then, simply execute dotnet run.

Expected behavior I expect to see listed the following in the commands section:

Screenshots

Schermata 2022-07-27 alle 16 41 03
nils-a commented 2 years ago

@Fed03 Sorry, but I am unable to reproduce that.

The code I used was:

using Spectre.Console;
using Spectre.Console.Cli;

var app = new CommandApp();
app.Configure(c =>
{
    c.AddCommand<SendNormalizedRecordToLime>("send");
    c.AddCommand<NormalizeLimeCsvCommand>("normalize");
});
return app.Run(args);

internal abstract class BaseCommand : Command
{
    public override int Execute(CommandContext context)
    {
        AnsiConsole.MarkupLine($"Hello from [green]{GetType().Name}[/].");

        return 0;
    }
}

internal sealed class SendNormalizedRecordToLime : BaseCommand
{
}

internal sealed class NormalizeLimeCsvCommand : BaseCommand
{
}

Which produced the expected result of:

➜  dotnet run
USAGE:
    test.dll [OPTIONS] <COMMAND>

OPTIONS:
    -h, --help       Prints help information
    -v, --version    Prints version information

COMMANDS:
    send
    normalize

However, I don't have access to a mac using iTerm2.

Could you try again in another terminal? (Am I correct in assuming your Rider Terminal is also setup to utilize iTerm2?)

Fed03 commented 2 years ago

@nils-a sorry for the late answer. I tried exactly with your code and experienced the same problem. I tried also with the built-in terminal and with hyper.is, trying also with different shells (sh, bash) other than the default zsh.

I want to highlight that if I add a simple description to at least one command, like this

c.AddCommand<SendNormalizedRecordToLime>("send").WithDescription("dd");
c.AddCommand<NormalizeLimeCsvCommand>("normalize");

we obtain the expected result

➜ dotnet run
USAGE:
    Spectre.Test.dll [OPTIONS] <COMMAND>

OPTIONS:
    -h, --help       Prints help information   
    -v, --version    Prints version information

COMMANDS:
    send         dd
    normalize   

let me know if I can help you

FrankRay78 commented 8 months ago

Closing this issue, feel free to reopen @Fed03 if it's still an issue and you can make available a complete project / Gist that reproduces it for you.