Cli: v2 bug: Value does not work with TimestampFlag

Created on 5 Jun 2020  路  5Comments  路  Source: urfave/cli

my urfave/cli version is

_2.2.0_

Checklist

  • [x] Are you running the latest v2 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v2 manual is here
  • [x] Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • [x] My project is using go modules.
  • [x] My project is using vendoring.
  • [ ] My project is automatically downloading the latest version.
  • [ ] I am unsure of what my dependency management setup is.

Describe the bug

Passing a Value to TimestampFlag does nothing.

To reproduce

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"

arev2 kinbug statuclaimed

All 5 comments

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 馃憤

Was this page helpful?
0 / 5 - 0 ratings