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

add Setter and Setv() #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add Setter and Setv() #240

wants to merge 1 commit into from

Conversation

CosmicToast
Copy link

See commit message for details.
This functionality is primarily useful for users of pflag as an API, as it allows to Visit arbitrary flags and give them a typed value without needing the various *Value types exposed (while also integrating with user-defined Value implementations).
In the future, it may be feasible to expand the given type uses of Setv().

Notes:

  1. uint32 is not convertible to an in32, because max(uint32) > max(int32)
  2. (u)int32 is not convertible to a float32, because of floating errors.
  3. int to uint conversions check against ints < 0.
  4. any value whose Set() calls append() does not pass through string types to Set()

this function allows one to set a Value that implements the Setter
interface programmatically

the setting should be absolute (since it isn't called by pflag
internally, there are no scenarios where repeatedly calling it would
happen)

internal disambiguation happens so that, say, "1" is a valid value for a
uint64

this also intelligently passes through string to Set() (unless this is a
Value where Set() is meant to be called repeatedly)
@CosmicToast
Copy link
Author

As a sidenote, this can be made (somewhat) shorter using the "reflect" package, but I wasn't sure which would be preferable.
If it is desired I can amend the PR easily.

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 this pull request may close these issues.

1 participant