diff --git a/console/application.go b/console/application.go index 5bd74ee66..2e4812fd4 100644 --- a/console/application.go +++ b/console/application.go @@ -8,17 +8,16 @@ import ( "github.com/goravel/framework/contracts/console" "github.com/goravel/framework/contracts/console/command" - "github.com/goravel/framework/support/env" ) type Application struct { - instance *cli.App - isArtisan bool + instance *cli.App + useArtisan bool } // NewApplication Create a new Artisan application. -// The artisan parameter is used by goravel/installer. -func NewApplication(name, usage, usageText, version string) console.Artisan { +// Will add artisan flag to the command if useArtisan is true. +func NewApplication(name, usage, usageText, version string, useArtisan bool) console.Artisan { instance := cli.NewApp() instance.Name = name instance.Usage = usage @@ -28,8 +27,8 @@ func NewApplication(name, usage, usageText, version string) console.Artisan { instance.OnUsageError = onUsageError return &Application{ - instance: instance, - isArtisan: env.IsArtisan(), + instance: instance, + useArtisan: useArtisan, } } @@ -59,7 +58,7 @@ func (r *Application) Call(command string) error { commands := []string{os.Args[0]} - if r.isArtisan { + if r.useArtisan { commands = append(commands, "artisan") } @@ -74,7 +73,7 @@ func (r *Application) CallAndExit(command string) { commands := []string{os.Args[0]} - if r.isArtisan { + if r.useArtisan { commands = append(commands, "artisan") } @@ -84,7 +83,7 @@ func (r *Application) CallAndExit(command string) { // Run a command. Args come from os.Args. func (r *Application) Run(args []string, exitIfArtisan bool) error { artisanIndex := -1 - if r.isArtisan { + if r.useArtisan { for i, arg := range args { if arg == "artisan" { artisanIndex = i diff --git a/console/application_test.go b/console/application_test.go index 0d9fc2afb..2588944e1 100644 --- a/console/application_test.go +++ b/console/application_test.go @@ -13,7 +13,7 @@ import ( var testCommand = 0 func TestRun(t *testing.T) { - cliApp := NewApplication("test", "test", "test", "test") + cliApp := NewApplication("test", "test", "test", "test", true) cliApp.Register([]console.Command{ &TestCommand{}, }) diff --git a/console/cli_helper_test.go b/console/cli_helper_test.go index 303c4216c..69e2c1db8 100644 --- a/console/cli_helper_test.go +++ b/console/cli_helper_test.go @@ -13,7 +13,7 @@ import ( ) func TestShowCommandHelp_HelpPrinterCustom(t *testing.T) { - cliApp := NewApplication("test", "test", "test", "test") + cliApp := NewApplication("test", "test", "test", "test", true) cliApp.Register([]console.Command{ &TestFooCommand{}, &TestBarCommand{}, diff --git a/console/service_provider.go b/console/service_provider.go index ca694a393..67674254b 100644 --- a/console/service_provider.go +++ b/console/service_provider.go @@ -17,7 +17,7 @@ func (receiver *ServiceProvider) Register(app foundation.Application) { name := "artisan" usage := "Goravel Framework" usageText := "artisan [global options] command [options] [arguments...]" - return NewApplication(name, usage, usageText, app.Version()), nil + return NewApplication(name, usage, usageText, app.Version(), true), nil }) }