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

Flag names missing in cli.Context.FlagNames() if set via env. variables #1263

Closed
4 of 7 tasks
alekna opened this issue Apr 3, 2021 · 4 comments · Fixed by #1537
Closed
4 of 7 tasks

Flag names missing in cli.Context.FlagNames() if set via env. variables #1263

alekna opened this issue Apr 3, 2021 · 4 comments · Fixed by #1537
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
Milestone

Comments

@alekna
Copy link

alekna commented Apr 3, 2021

my urfave/cli version is

v2.3.0

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.
  • My project is automatically downloading the latest version.
  • I am unsure of what my dependency management setup is.

Describe the bug

Flag names missing in cli.Context.FlagNames() if set via env. variables.

To reproduce

package main

import (
	"fmt"
	"github.com/urfave/cli/v2"
	"log"
	"os"
)

func main() {
	app := &cli.App{
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "testvar",
				EnvVars: []string{"TESTVAR"},
			},
		}, Action: func(c *cli.Context) error {
			fmt.Println("FlagNames()\t", c.FlagNames())
			fmt.Println("testvar\t\t", c.String("testvar"))
			return nil
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

Observed behavior

$ ./main --testvar testval
FlagNames()	 [testvar]
testvar		 testval
$ TESTVAR=testval ./main 
FlagNames()	 []
testvar		 testval

Expected behavior

I expect cli.Context.FlagNames() to return flag names irrespectively of which way they were set.

Run go version and paste its output here

$ go version
go version go1.16.2 linux/amd64
@alekna alekna 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 Apr 3, 2021
@alekna alekna changed the title Flags missing in cli.Context.FlagNames() if set as env. variables Flags names missing in cli.Context.FlagNames() if set via env. variables Apr 3, 2021
@alekna alekna changed the title Flags names missing in cli.Context.FlagNames() if set via env. variables Flag names missing in cli.Context.FlagNames() if set via env. variables Apr 3, 2021
@dearchap
Copy link
Contributor

dearchap commented Apr 7, 2021

Context.FlagNames returns the flags that have been specified and set on the command line . But it does make sense to return those that have been set(either by env or cli)

@stale
Copy link

stale bot commented Jul 8, 2021

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jul 8, 2021
@alekna
Copy link
Author

alekna commented Jul 19, 2021

Bump. The Issue is still unfixed.

@stale
Copy link

stale bot commented Jul 19, 2021

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jul 19, 2021
@alekna alekna changed the title Flag names missing in cli.Context.FlagNames() if set via env. variables v2 bug: Flag names missing in cli.Context.FlagNames() if set via env. variables Jul 19, 2021
@meatballhat meatballhat changed the title v2 bug: Flag names missing in cli.Context.FlagNames() if set via env. variables Flag names missing in cli.Context.FlagNames() if set via env. variables Apr 21, 2022
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

Successfully merging a pull request may close this issue.

3 participants