My urfave/cli version is
3.10.1
Checklist
Dependency Management
- My project is using go modules.
Describe the bug
Subcommands don't seem to get passed their arguments correctly.
To reproduce
package bug_test
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
)
func Example() {
_ = Root().Run(context.Background(), []string{"example", "sub", "value"})
//Output:
// value
}
func Root() *cli.Command {
return &cli.Command{
Name: "example",
Commands: []*cli.Command {
Sub(),
},
}
}
func Sub() *cli.Command {
return &cli.Command {
Name: "sub",
Arguments: []cli.Argument{
&cli.StringArg{
Name: "test",
},
},
Action: func(ctx context.Context, c *cli.Command) error {
fmt.Print(c.Args().First())
return nil
},
}
}
Observed behavior
--- FAIL: Example (0.00s)
got:
want:
value
FAIL
FAIL github.com/tvanriel/minimal-example-urfave-cli-subcommand-bug 0.002s
FAIL
Expected behavior
I would have expected the included code to print value, as was passed in the arguments.
Additional context
Want to fix this yourself?
I did some digging and it seems to be related to a shadowed reference to rargs that gets set while parsing args and then cleaned before being saved in cmd.parsedArgs but couldn't get a fix to work.
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.26.4-X:nodwarf5 linux/amd64
Run go env and paste its output here
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/tvanriel/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/tvanriel/.config/go/env'
GOEXE=''
GOEXPERIMENT='nodwarf5'
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3424211875=/tmp/go-build
-gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/tvanriel/Projects/Personal/minimal-example-urfave-cli-subcommand-bug/go.mod'
GOMODCACHE='/home/tvanriel/go/pkg/mod'
GONOPROXY='gitlab.figonet.nl,gitlab.bauwatch.tech'
GONOSUMDB='gitlab.figonet.nl,gitlab.bauwatch.tech'
GOOS='linux'
GOPATH='/home/tvanriel/go'
GOPRIVATE='gitlab.figonet.nl,gitlab.bauwatch.tech'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/tvanriel/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.4-X:nodwarf5'
GOWORK=''
PKG_CONFIG='pkg-config'
My urfave/cli version is
3.10.1
Checklist
Dependency Management
Describe the bug
Subcommands don't seem to get passed their arguments correctly.
To reproduce
Observed behavior
Expected behavior
I would have expected the included code to print
value, as was passed in the arguments.Additional context
Want to fix this yourself?
I did some digging and it seems to be related to a shadowed reference to
rargsthat gets set while parsing args and then cleaned before being saved incmd.parsedArgsbut couldn't get a fix to work.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 versionand paste its output hereRun
go envand paste its output here