Closed devnut closed 4 months ago
@devnut Whats the actual issue you are facing ?
Fullname() is returning "subcommand", not "command subcommand". The following equivalent code before version 2.20.0, it did.
Example:
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "boom",
Usage: "make an explosive entrance",
Commands: []*cli.Command{
&cli.Command{
Name: "foo",
Usage: "foo I say",
Action: func(c *cli.Context) error {
fmt.Println("foo! I say!")
fmt.Printf("expecting '%s', bot got FullName() '%s', HelpName '%s'\n", "foo", c.Command.FullName(), c.Command.HelpName)
return nil
},
Subcommands: []*cli.Command{
&cli.Command{
Name: "bar",
Usage: "bar I say",
Action: func(c *cli.Context) error {
fmt.Println("bar! I say!")
fmt.Printf("expecting '%s', bot got FullName() '%s', HelpName '%s'\n", "foo bar", c.Command.FullName(), c.Command.HelpName)
return nil
},
},
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
Output:
$ go get github.com/urfave/cli/v2
go: upgraded github.com/urfave/cli/v2 v2.19.3 => v2.27.1
$ go run main.go
NAME:
boom - make an explosive entrance
USAGE:
boom [global options] command [command options]
COMMANDS:
foo foo I say
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
$ go run main.go foo
foo! I say!
expecting 'foo', bot got FullName() 'foo', HelpName 'boom foo'
$ go run main.go foo bar
bar! I say!
expecting 'foo bar', bot got FullName() 'bar', HelpName 'boom foo bar'
Contrast this with v2.19.3:
$ go get github.com/urfave/cli/v2@v2.19
go: downgraded github.com/urfave/cli/v2 v2.27.1 => v2.19.3
$ go run main.go
NAME:
boom - make an explosive entrance
USAGE:
boom [global options] command [command options] [arguments...]
COMMANDS:
foo foo I say
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help (default: false)
$ go run main.go foo
foo! I say!
expecting 'foo', bot got FullName() '', HelpName ''
$ go run main.go foo bar
bar! I say!
expecting 'foo bar', bot got FullName() 'foo bar', HelpName 'boom foo bar'
I could make HelpName work, but it seems to have changed too.
If FullName() returned in 1.21 what it did in 1.20, that would be fine as the work-around we have for "foo" returning an empty string would continue to work, which involves using "HelpName".
@devnut Yes the FullName was actually buggy as you can see from your example. It wasnt consistent so FullName returns the name of the command and HelpName the display name in help.
My urfave/cli version is
2.19.3
Checklist
Dependency Management
Describe the bug
In urfave 2.19.3 when calling FullName() it is constructed from c.commandNamePath.
In 2.19.3 there is code in startApp() that does not seem to be in 2.20.0-2.21.1
To reproduce
c.Command.FullName() (where c is *cli.Context of a subcommand)
Observed behavior
Only the "subcommand" name is printed
Expected behavior
FullName() would emit "command subcommand"
Additional context
Add any other context about the problem 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 hereRun
go env
and paste its output here