Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: artisan bug #802

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

"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 @@
instance.OnUsageError = onUsageError

return &Application{
instance: instance,
isArtisan: env.IsArtisan(),
instance: instance,
useArtisan: useArtisan,
}
}

Expand Down Expand Up @@ -59,7 +58,7 @@

commands := []string{os.Args[0]}

if r.isArtisan {
if r.useArtisan {
commands = append(commands, "artisan")
}

Expand All @@ -74,7 +73,7 @@

commands := []string{os.Args[0]}

if r.isArtisan {
if r.useArtisan {

Check warning on line 76 in console/application.go

View check run for this annotation

Codecov / codecov/patch

console/application.go#L76

Added line #L76 was not covered by tests
commands = append(commands, "artisan")
}

Expand All @@ -84,7 +83,7 @@
// 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 @@
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

Check warning on line 20 in console/service_provider.go

View check run for this annotation

Codecov / codecov/patch

console/service_provider.go#L20

Added line #L20 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should set true manually, otherwise, go run . will be the same as go run . artisan.

})
}

Expand Down
Loading