-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/bugdescribes or fixes a bugdescribes or fixes a bugstatus/triagemaintainers still need to look into thismaintainers still need to look into this
Description
My urfave/cli version is
github.com/urfave/cli/v2 v2.25.3
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
When defining a TimestampFlag with an alias, calling ctx.IsSet on the name (not the alias) returns false when the alias is used in the command line.
To reproduce
https://go.dev/play/p/WMR_blIb2kf
package main
import (
"fmt"
"log"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Flags: []cli.Flag{
&cli.TimestampFlag{
Name: "meeting",
Aliases: []string{"m"},
Layout: "2006-01-02T15:04:05",
},
},
Action: func(cCtx *cli.Context) error {
fmt.Printf("meeting is set = %v\n", cCtx.IsSet("meeting"))
fmt.Printf("meeting = %s\n", cCtx.Timestamp("meeting").String())
return nil
},
}
if err := app.Run([]string{"exe", "--meeting", "2019-08-12T15:04:05"}); err != nil {
log.Fatal(err)
}
if err := app.Run([]string{"exe", "-m", "2019-08-12T15:04:05"}); err != nil {
log.Fatal(err)
}
}meeting is set = true
meeting = 2019-08-12 15:04:05 +0000 UTC
meeting is set = false <-- should be true
meeting = 2019-08-12 15:04:05 +0000 UTC
Observed behavior
cCtx.IsSet("meeting") returns false for the call with -m=...
Expected behavior
cCtx.IsSet("meeting") should return true if using the alias -m=...
Additional context
Line 199 in acbbbf2
| _ = set.Set(name, ff.Value.String()) |
Issue seems to be here, in copyFlag, when converting the value of the flag to String, can't be decoded by golang flag package
Run go version and paste its output here
go version go1.19.8 darwin/amd64
Run go env and paste its output here
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tchandelle/Library/Caches/go-build"
GOENV="/Users/tchandelle/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tchandelle/.asdf/installs/golang/1.19.8/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tchandelle/.asdf/installs/golang/1.19.8/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/tchandelle/.asdf/installs/golang/1.19.8/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/tchandelle/.asdf/installs/golang/1.19.8/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.8"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/tchandelle/git/nodeum/nodeum-v2/data_management/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wc/1rp4395x1_bf48vw43ftrm1r0000gn/T/go-build97822141=/tmp/go-build -gno-record-gcc-switches -fno-common"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/bugdescribes or fixes a bugdescribes or fixes a bugstatus/triagemaintainers still need to look into thismaintainers still need to look into this