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

how to set nil as default value in BoolVar? #2142

Closed
OpenWaygate opened this issue May 5, 2024 · 1 comment
Closed

how to set nil as default value in BoolVar? #2142

OpenWaygate opened this issue May 5, 2024 · 1 comment

Comments

@OpenWaygate
Copy link

I want to keep a variable as nil except explicitly set, but only true or false is allowed.

myCmd.Flags().BoolVar(&isMine, "isMine", nil, "")
@OpenWaygate OpenWaygate changed the title how to set nil as default value? how to set nil as default value in BoolVar? May 5, 2024
@marckhouzam
Copy link
Collaborator

In Go a bool cannot be nil but only true or false. If you’re thinking of the pointer you’re passing in, that cannot be nil as it must represent a location where cobra can write true or false

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

No branches or pull requests

2 participants