spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

--version not showing version when default command set

Open yufeih opened this issue 2 years ago • 4 comments

Information

  • OS: [all]
  • Version: [0.46.0]

To Reproduce

  • Set default command using SetDefaultCommand
  • Run mycmd --version
  • Version not shown

Expected behavior Shows version instead of executing default command

Additional context

Seemingly caused by this check

yufeih avatar Apr 14 '23 13:04 yufeih

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

FrankRay78 avatar Jul 03 '23 19:07 FrankRay78

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

my522cn avatar Jul 12 '24 03:07 my522cn

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

FrankRay78 avatar Aug 01 '24 11:08 FrankRay78

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

FrankRay78 avatar Aug 03 '24 21:08 FrankRay78

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

0.49.0 Still not work

my522cn avatar Nov 28 '24 09:11 my522cn

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

0.49.0 Still not work

It's not fixed, however once the PR above (#1663) is merged, it will be!

FrankRay78 avatar Nov 28 '24 10:11 FrankRay78

As a workaround, add this to the start of the Execute{Async} method of the default command:

if ( context.Arguments.Contains( "--version" )
     || context.Arguments.Contains( "-v" ) )
{
	AnsiConsole.WriteLine( "Version info here" );
	return 0;
}

KnapSac avatar Feb 18 '25 12:02 KnapSac

We are unfortunately experiencing a lack of maintainer bandwidth to review PR's, otherwise this would be fixed by the attached PR @KnapSac

FrankRay78 avatar Feb 18 '25 13:02 FrankRay78

That's unfortunate. Luckily I can work around this issue for now, so no worries!

KnapSac avatar Feb 18 '25 13:02 KnapSac