Add options to implement flag.Value and pflag.Value methods #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello
There are two useful interfaces that I often forget to implement when I am using the enumeration types on command line flags
There are two common interfaces:
Since the
pflag.Value
IS Aflag.Value
, with one extra method, but not all people what to implement it, I add two new explicit command line flags (disabled by default):if both are enabled, we will consider only the pflag case.
this patch is incredible helpfut since I often discover that the Value interface is needed in runtime.
Since some tests became more complex to understand, change the signature of the generate method to receive an private option type, a struct, to improve readability and simplify the program flags itself (instead having a lot of global variables)
There are other merge requests to improve tests and stop using deprecated ioutil package, I will not touch on this part again ( see #103 )
In the pflag case, the
Type() string
method will return all possible string values joined by|
-- and this is helpful to quickly understand the options using a notation that is very common. If someone needs to return a different message, they can just use the flag.Value option and create a customType() string