From 6a2134481df127e052282c97621bdbc282ef5858 Mon Sep 17 00:00:00 2001 From: Bowen Date: Tue, 30 Dec 2025 16:37:40 +0800 Subject: [PATCH 1/2] fix: [#850] artisan help incorrect behavior --- console/application.go | 2 +- console/cli_helper_test.go | 8 ++++---- console/console/help_command.go | 35 --------------------------------- console/console/list_command.go | 13 +++++------- console/service_provider.go | 3 +-- 5 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 console/console/help_command.go diff --git a/console/application.go b/console/application.go index b0eade2b1..522034d2c 100644 --- a/console/application.go +++ b/console/application.go @@ -124,7 +124,7 @@ func (r *Application) Run(args []string, exitIfArtisan bool) error { if artisanIndex != -1 { command := r.command() if artisanIndex+1 == len(args) { - args = append(args, "help") + args = append(args, "list") } cliArgs := append([]string{args[0]}, args[artisanIndex+1:]...) diff --git a/console/cli_helper_test.go b/console/cli_helper_test.go index d8041da13..a3e3b0aeb 100644 --- a/console/cli_helper_test.go +++ b/console/cli_helper_test.go @@ -26,7 +26,7 @@ func TestShowCommandHelp_HelpPrinterCustom(t *testing.T) { cliApp.Register([]contractsconsole.Command{ &TestFooCommand{}, &TestBarCommand{}, - console.NewHelpCommand(), + console.NewListCommand(), }) tests := []struct { @@ -35,8 +35,8 @@ func TestShowCommandHelp_HelpPrinterCustom(t *testing.T) { containsOutput []string }{ { - name: "print app help", - call: "help", + name: "print commands list", + call: "list", containsOutput: []string{ color.Yellow().Sprint("Usage:"), color.Yellow().Sprint("Global options:"), @@ -144,7 +144,7 @@ Global options: -v, --version Print the version Available commands: - help Shows a list of commands + list List commands test: test:bar Test command test:foo Test command`, diff --git a/console/console/help_command.go b/console/console/help_command.go deleted file mode 100644 index a09081cf3..000000000 --- a/console/console/help_command.go +++ /dev/null @@ -1,35 +0,0 @@ -package console - -import ( - "github.com/urfave/cli/v3" - - "github.com/goravel/framework/contracts/console" - "github.com/goravel/framework/contracts/console/command" -) - -type HelpCommand struct { -} - -func NewHelpCommand() *HelpCommand { - return &HelpCommand{} -} - -// Signature The name and signature of the console command. -func (r *HelpCommand) Signature() string { - return "help" -} - -// Description The console command description. -func (r *HelpCommand) Description() string { - return "Shows a list of commands" -} - -// Extend The console command extend. -func (r *HelpCommand) Extend() command.Extend { - return command.Extend{} -} - -// Handle Execute the console command. -func (r *HelpCommand) Handle(ctx console.Context) error { - return cli.ShowAppHelp(ctx.Instance()) -} diff --git a/console/console/list_command.go b/console/console/list_command.go index e050140b5..b1fdddb0a 100644 --- a/console/console/list_command.go +++ b/console/console/list_command.go @@ -3,16 +3,13 @@ package console import ( "github.com/goravel/framework/contracts/console" "github.com/goravel/framework/contracts/console/command" + "github.com/urfave/cli/v3" ) -type ListCommand struct { - artisan console.Artisan -} +type ListCommand struct{} -func NewListCommand(artisan console.Artisan) *ListCommand { - return &ListCommand{ - artisan: artisan, - } +func NewListCommand() *ListCommand { + return &ListCommand{} } // Signature The name and signature of the console command. @@ -32,5 +29,5 @@ func (r *ListCommand) Extend() command.Extend { // Handle Execute the console command. func (r *ListCommand) Handle(ctx console.Context) error { - return r.artisan.Call("--help") + return cli.ShowAppHelp(ctx.Instance()) } diff --git a/console/service_provider.go b/console/service_provider.go index cc81c53f1..0c5d36053 100644 --- a/console/service_provider.go +++ b/console/service_provider.go @@ -50,10 +50,9 @@ func (r *ServiceProvider) registerCommands(app foundation.Application) { } artisanFacade.Register([]consolecontract.Command{ - console.NewListCommand(artisanFacade), + console.NewListCommand(), console.NewKeyGenerateCommand(configFacade), console.NewMakeCommand(), console.NewBuildCommand(configFacade), - console.NewHelpCommand(), }) } From f95ee3b91188c8e544b033d3daca68d5274721b1 Mon Sep 17 00:00:00 2001 From: Bowen Date: Tue, 30 Dec 2025 16:55:41 +0800 Subject: [PATCH 2/2] optimize --- console/console/list_command.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/console/console/list_command.go b/console/console/list_command.go index b1fdddb0a..d48fcf5cc 100644 --- a/console/console/list_command.go +++ b/console/console/list_command.go @@ -1,9 +1,10 @@ package console import ( + "github.com/urfave/cli/v3" + "github.com/goravel/framework/contracts/console" "github.com/goravel/framework/contracts/console/command" - "github.com/urfave/cli/v3" ) type ListCommand struct{}