proposal: flag: add support for parsing big numbers #45751
It would be nice to add support in the flag package to parse a flag directly to a big integer instead of having to parse as a string first and then try to parse the string as a big int in our code. Something like the following:
var candidate = flag.BigInt("n", "3853882583591558728", "Run integer factorization for this number")
If such a proposal makes sense, we might as well add support for all math/big types (Float, Int, Rat).
The text was updated successfully, but these errors were encountered:
This would cause the
Perhaps, the API should be:
func TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string)
and usage could be like:
var n big.Int flag.TextVar(&n, "n", big.NewInt(3853882583591558728), "Run integer factorization for this number")
var t time.Time flag.TextVar(&t, "start_time", time.Now(), "Start processing logs at this time."
I see several advantages of this approach:
There is some type safety problems with my proposed API, where the
If it's just a one-off, it can be even shorter using the new