urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.9k stars 1.69k forks source link

FilePath does not take precedence over EnvVar #1866

Closed zc-devs closed 4 months ago

zc-devs commented 4 months ago

My urfave/cli version is v2.27.1

Dependency Management

Describe the bug

FilePath does not take precedence over EnvVar as described in documentation.

To reproduce

  1. Set some flag
    &cli.StringFlag{
    EnvVars:  []string{"WOODPECKER_DATABASE_DATASOURCE"},
    Name:     "datasource",
    Usage:    "database driver configuration string",
    Value:    "woodpecker.sqlite",
    FilePath: os.Getenv("WOODPECKER_DATABASE_DATASOURCE_FILE"),
    },
  2. Set EnvVar:
    export WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite
  3. Set FilePath variable:
    export WOODPECKER_DATABASE_DATASOURCE_FILE=/run/secrets/woodpecker-datasource.conf
  4. Get /var/lib/woodpecker/woodpecker.sqlite instead /run/secrets/woodpecker-datasource.conf in datasource flag.

Observed behavior

Step 4.

Expected behavior

FilePath should take precedence over EnvVar. So, I should get /run/secrets/woodpecker-datasource.conf in datasource flag.

Additional context

https://github.com/woodpecker-ci/woodpecker/issues/3389