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

App execute wrong command when default command is set. #1548

Closed
smalnote opened this issue Oct 25, 2022 · 0 comments · Fixed by #1549
Closed

App execute wrong command when default command is set. #1548

smalnote opened this issue Oct 25, 2022 · 0 comments · Fixed by #1549
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@smalnote
Copy link
Member

My urfave/cli version is

( Put the version of urfave/cli that you are using here )

Checklist

  • [✅] Are you running the latest v2 release? The list of releases is here.
  • [✅] Did you check the manual for your release? The v2 manual is here
  • [✅] Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

A clear and concise description of what the bug is.

To reproduce

App executes wrong command when default command is set.

// in main.go file
var app = cli.App{
	Name:           "inspector",
	DefaultCommand: "inspect",
	Commands: []*cli.Command{
		{
			Name:  "inspect",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:  "filename",
				},
			},
			Action: func(ctx *cli.Context) error {
				log.Print("inspect")
				return nil
			},
		},
		{
			Name:  "declare",
			Flags: []cli.Flag{
				&cli.StringSliceFlag{
					Name:     "filename",
				},
			},
			Action: func(ctx *cli.Context) error {
				log.Print("declare")
				return nil
			},
		},
	},
}
$go run ./main.go declare --filename=abc

Observed behavior

Run the default command inspect rather than the specified command declare.
$go run main.go declare --filename=abc
$2022/10/25 11:57:04 inspect

Expected behavior

Run the command declare.

What would you have expected to happen immediately after the
reproduction steps above?

Additional context

Add any other context about the problem here.

If the issue relates to a specific open source GitHub repo, please
link that repo here.

If you can reproduce this issue with a public CI system, please
link a failing build here.

Want to fix this yourself?

We'd love to have more contributors on this project! If the fix for
this bug is easily explained and very small, feel free to create a
pull request for it.

Run go version and paste its output here

go version go1.19.1 linux/amd64

Run go env and paste its output here

# paste `go env` output in here
@smalnote smalnote added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Oct 25, 2022
@smalnote smalnote changed the title your bug title goes here App execute wrong command when default command is set. Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant