spectreconsole / spectre.console

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

--version not showing version when default command set #1216

Open yufeih opened 1 year ago

yufeih commented 1 year ago

Information

To Reproduce

Expected behavior Shows version instead of executing default command

Additional context

Seemingly caused by this check

FrankRay78 commented 1 year ago

FYI. I've nearly fixed this and will submit a PR soon (likely in the coming weeks).

my522cn commented 2 months ago

I don‘t think this bug has fixed. When I using SetDefaultCommand, -v is still not work. spectre.console version: 0.49.1

FrankRay78 commented 1 month ago

I'll take a look @my522cn, please be on hand if I need help reproducing it.

FrankRay78 commented 1 month ago

Unfortunately it's still broken in 0.49.1 @my522cn

Here is my command and application:

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

public class EmptyCommand : Command<EmptyCommandSettings>
{
    public override int Execute(CommandContext context, EmptyCommandSettings settings)
    {
        AnsiConsole.MarkupLine("Hello world");
        return 0;
    }
}

public static class Program
{
    public static int Main(string[] args)
    {
        var app = new CommandApp();

        app.SetDefaultCommand<EmptyCommand>();
        app.Configure(config =>
        {
            config.SetApplicationVersion("1.0");
        });

        return app.Run(args);
    }
}

The default command is executed, not the version shown:

image

Expected behavior Shows version instead of executing default command