cobra icon indicating copy to clipboard operation
cobra copied to clipboard

how to set `nil` as default value in `BoolVar`?

Open OpenWaygate opened this issue 9 months ago • 1 comments

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 avatar May 05 '24 13:05 OpenWaygate

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

marckhouzam avatar May 05 '24 15:05 marckhouzam