Skip to content

Commit

Permalink
fix: artisan bug (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl authored Dec 31, 2024
1 parent 5f335b1 commit e8dea15
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
19 changes: 9 additions & 10 deletions console/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion console/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
})
Expand Down
2 changes: 1 addition & 1 deletion console/cli_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 1 addition & 1 deletion console/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down

0 comments on commit e8dea15

Please sign in to comment.