Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsSet for aliases of TimestampFlag doesn't work #1731

Closed
3 tasks done
tchandelle opened this issue May 16, 2023 · 1 comment
Closed
3 tasks done

IsSet for aliases of TimestampFlag doesn't work #1731

tchandelle opened this issue May 16, 2023 · 1 comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@tchandelle
Copy link

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

cli/flag.go

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"
@tchandelle tchandelle added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels May 16, 2023
@dearchap
Copy link
Contributor

@tchandelle Yes this is definitely a bug. Would you like to submit a PR to fix this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants