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

PFlag/Cobra compatibility in prefork #1782

Closed
mhkarimi1383 opened this issue May 31, 2024 · 1 comment · Fixed by #1783
Closed

PFlag/Cobra compatibility in prefork #1782

mhkarimi1383 opened this issue May 31, 2024 · 1 comment · Fixed by #1783

Comments

@mhkarimi1383
Copy link

mhkarimi1383 commented May 31, 2024

I'm using Cobra in my projects to manage my commands and Cobra is using PFlag to manage flags and since it's using POSIX/GNU-style (with -- instead of -) I'm getting that error below

After adding snippet below to add compatibility I'm getting

      --prefork-child   Is a child process
unknown shorthand flag: 'p' in -prefork-child
unknown shorthand flag: 'p' in -prefork-child
import (
	flag "github.com/spf13/pflag"
	goflag "flag"
)

func init() {
	flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
	flag.Parse()
}

Also without

flag.Parse()

I'm getting

Error: unknown shorthand flag: 'p' in -prefork-child
Error: unknown shorthand flag: 'p' in -prefork-child
erikdubbelboer added a commit that referenced this issue Jun 1, 2024
It's better to use an environment variable as they are more standard.
They way flags are parsed isn't standardized within the Go ecosystem.

Fixes: #1782
@erikdubbelboer
Copy link
Collaborator

I agree, using a flag for this is not the best way to do it, see: #1783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants