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

Timestamp flags don't work with environment variables #1755

Closed
3 tasks done
victorkt opened this issue Jun 13, 2023 · 2 comments
Closed
3 tasks done

Timestamp flags don't work with environment variables #1755

victorkt opened this issue Jun 13, 2023 · 2 comments
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

@victorkt
Copy link

My urfave/cli version is

v2.25.6

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.
  • My project is using vendoring.

Describe the bug

Timestamp flags don't seem to work with environment variables. When passing the value as an env var, the value is unchanged. This doesn't happen when passing values as arguments.

To reproduce

I've tested it with the following code:

package main

import (
	"fmt"
	"log"
	"os"
	"time"

	"github.com/urfave/cli/v2"
)

var someTimestampFlag cli.Timestamp

func main() {
	app := cli.NewApp()
	app.Flags = []cli.Flag{
		&cli.TimestampFlag{
			Name:        "some-timestamp-flag",
			EnvVars:     []string{"SOME_TIMESTAMP_FLAG"},
			Layout:      time.RFC3339,
			Destination: &someTimestampFlag,
			Required:    true,
		},
	}
	app.Action = func(c *cli.Context) error {
		fmt.Println("env var:", os.Getenv("SOME_TIMESTAMP_FLAG"))
		fmt.Println("flag:", someTimestampFlag.Value())
		return nil
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

Observed behavior

$ SOME_TIMESTAMP_FLAG=2021-03-02T06:20:00Z go run main.go
env var: 2021-03-02T06:20:00Z
flag: <nil>

$ go run main.go --some-timestamp-flag=2021-03-02T06:20:00Z
env var: 
flag: 2021-03-02 06:20:00 +0000 UTC

Expected behavior

I'd expect the flag contained the provided date in both runs.

Run go version and paste its output here

$ go version
go version go1.20.5 darwin/arm64
@victorkt victorkt 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 Jun 13, 2023
@dearchap
Copy link
Contributor

@victorkt Thank you for raising this issue. Can you see if the PR fixes your issue ?

@victorkt
Copy link
Author

@dearchap thanks for the quick response. yes, that seems to fix the problem.

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