-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Command-actions with subcommands do not receive initialized context #1217
Comments
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
This bug persists. Please keep the bug open. |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
Please s not close this. |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
@nicerobot try implementing a(n essentially empty) |
No luck Run this updated Playground Examplepackage main
import (
"fmt"
"github.com/urfave/cli/v2"
)
//
func main() {
before := func(ctx *cli.Context) error {
fmt.Printf("\nbefore %#v\n", ctx.Command)
return nil
}
action := func(ctx *cli.Context) error {
fmt.Printf("action %#v\n", ctx.Command)
return nil
}
after := func(ctx *cli.Context) error {
fmt.Printf("after %#v\n", ctx.Command)
return nil
}
sub := cli.Commands{{Name: "sub", Usage: "sub", Action: action, After: after, Before: before}}
withsub := &cli.Command{Name: "withsub", Usage: "withsub", Action: action, After: after, Before: before, Subcommands: sub}
withoutsub := &cli.Command{Name: "withoutsub", Usage: "withoutsub", Action: action, After: after, Before: before}
app := &cli.App{Commands: cli.Commands{withsub, withoutsub}}
// These two work fine
_ = app.Run([]string{"play", "withsub", "sub"})
_ = app.Run([]string{"play", "withoutsub"})
// This one does not pass a properly initialized context
fmt.Println("Notice the Command.Name is empty:")
_ = app.Run([]string{"play", "withsub"})
// It calls this: https://github.com/urfave/cli/blob/master/command.go#L94
// without first doing this: https://github.com/urfave/cli/blob/master/command.go#L162
} |
@nicerobot The latest release which optimizes the app/cmd code actually fixed this. Can you test ? |
my urfave/cli version is
github.com/urfave/cli/v2 v2.3.0
Checklist
Dependency Management
Describe the bug
Calling commands that have subcommands does not pass an initialized context to the action.
To reproduce
Run this Playground Example
Observed behavior
Expected behavior
When a command is called that has a subcommand but the subcommand is not on the command-line, the action receives a context initialized with the right command.
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, free free to create a pull request for it.
Run
go version
and paste its output hereRun
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: