cli
cli copied to clipboard
`SkipArgReorder=false` reorders args after `--`
My urfave/cli version is
v1.22.9
Checklist
- [x] Are you running the latest v1 release? The list of releases is here.
- [x] Did you check the manual for your release? The v1 manual is here.
- [x] 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
SkipArgReorder=false reorders argumentss after -- as shown in the following reproducer.
Is this an expected behaviour?
To reproduce
The following is a simple code to print args parsed by this library (i.e. cli.Context.Args()).
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
func main() {
testCommand := cli.Command{
Name: "test",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "t",
},
},
Action: func(context *cli.Context) error {
fmt.Println(context.Args())
return nil
},
}
testCommand.SkipArgReorder = false
withReordering := cli.NewApp()
withReordering.Commands= []cli.Command{testCommand}
if err := withReordering.Run(os.Args); err != nil {
panic(err)
}
testCommand.SkipArgReorder = true
withoutReordering := cli.NewApp()
withoutReordering.Commands= []cli.Command{testCommand}
if err := withoutReordering.Run(os.Args); err != nil {
panic(err)
}
}
Observed behavior
Let's say running it with the following arguments.
# go run main.go test -t -- foo -t
This produces different results according to SkipArgReorder
SkipArgReorder |
cli.Context.Args() |
|---|---|
true |
[foo -t] |
false |
[-t foo] |
Expected behavior
SkipArgReorder=false should not reorder arguments after -- and allow Action function to parse them.
Run go version and paste its output here
go version go1.18 linux/amd64
Run go env and paste its output here
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ktock/.cache/go-build"
GOENV="/home/ktock/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ktock/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ktock/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ktock/go/src/github.com/ktock/urfave-cli-reordering-test/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1016098905=/tmp/go-build -gno-record-gcc-switches"
@ktock This is definitely not expected behavior. I fully admit that the arg reordering in the v1 series has long been a source of bugs and this is one of the reasons why reordering was removed in the v2 series. Are you able to update the relevant code to use the latest v2.x instead?