-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: flag: add support for parsing big numbers #45751
Comments
This would cause the As a counter-proposal, perhaps 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") or like: 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 |
It is so easy to write your own implementation of flag.Value that adding more types of flags to the package requires a very strong justification. |
If it's just a one-off, it can be even shorter using the new
|
A detriment of I filed #45754 as a counter proposal based on my comment above. |
FWIW, the original implementation of flag.Func took a default value string, but it was dropped because you can just add “(default x)” to the usage string. |
An advantage of having the |
Based on the discussion this proposal will clearly not be accepted, so closing. Please comment if you disagree. Thanks. |
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:
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: