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

global bool flags does not work #1717

Closed
3 tasks done
tomasweigenast opened this issue Apr 9, 2023 · 5 comments
Closed
3 tasks done

global bool flags does not work #1717

tomasweigenast opened this issue Apr 9, 2023 · 5 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

@tomasweigenast
Copy link

My urfave/cli version is

github.com/urfave/cli/v2 v2.25.1

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.

The bug

When I set a global bool flag, like the following:

app = &cli.App{
		CustomAppHelpTemplate: helpText,
		CommandNotFound:       cli.ShowCommandCompletions,
		Flags: []cli.Flag{
			&cli.BoolFlag{
				Name:        "verbose",
				Required:    false,
				Hidden:      false,
				Destination: &verboseLogging,
				Usage:       "Print all logs to the console",
			},
		},
	}

When I run another command, like plugin info, it says: Incorrect Usage: flag provided but not defined: -verbose and at the end of the help text: flag provided but not defined: -verbose

But now, when I mark the flag as required, if I run the same command, the cli says: Required flag "verbose" not set lol.
The full command is: go run . plugin info --verbose. plugin is a command and info a subcommand that actually performs some action.

@tomasweigenast tomasweigenast 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 9, 2023
@dearchap
Copy link
Contributor

dearchap commented Apr 9, 2023

@tomasweigenast This is expected behavior in v2. v3/main has support for this by setting the Persistent field in the flag.

https://github.com/urfave/cli/blob/main/flag_impl.go#L92

@tomasweigenast
Copy link
Author

When it will be released?

@dearchap
Copy link
Contributor

v3 is in alpha. You can use it right now by importing "github.com/urfave/cli/v3"

@tomasweigenast
Copy link
Author

@tomasweigenast This is expected behavior in v2. v3/main has support for this by setting the Persistent field in the flag.

https://github.com/urfave/cli/blob/main/flag_impl.go#L92

I tried it but it does not work when the flag is specified last.

./mytool --the-flag command subcommand -> It works
./mytool command subcommand --the-flag -> It does not work

I tried with the Persistent flag and without

@dearchap
Copy link
Contributor

dearchap commented Jul 6, 2023

Yes you have to give all the flags before args

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