_2.2.0_
Passing a Value to TimestampFlag does nothing.
package main
import (
"fmt"
"github.com/urfave/cli/v2"
"log"
"os"
"time"
)
func main() {
var today = cli.NewTimestamp(time.Now())
app := &cli.App{
Commands: []*cli.Command{{
Name: "sync",
Flags: []cli.Flag{
&cli.TimestampFlag{
Name: "from",
Layout: "2006-01-02",
Value: today,
},
},
Action: func(c *cli.Context) error {
fmt.Println(c.Timestamp("from"))
return nil
},
}},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
go install && go mymodule sync
md5-d00504afcac0303dd3b2624e42efde97
go version go1.14.2 linux/amd64
md5-e8b106e8fdf0e9c26abb51d3ea3876de
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/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"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/exfin/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build096471754=/tmp/go-build -gno-record-gcc-switches"
I guess it's because of this: https://github.com/urfave/cli/blob/master/flag_timestamp.go#L121
Default value always gets override.
So i think this can be fixed by adding an if like:
if f.Value == nil {
f.Value = &Timestamp{}
}
@aloababa yes, seems like this is the place. Thanks for pointing out! I will open a PR to fix this on the weekend.
Sounds good, cc me when you're ready for a review ^^
@lynncyrin do you guys need any help on other issues? I saw a few that might be stale but I don't wanna to intrude ^^
Yes we could totally use help with stale or help wanted issues 馃憤