StringSlice CLI should replace default values #98
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.
I can confirm
PortVarP()
is affected as well:Honestly I don't like this solution, it breaks the concept of having the StringSlice exactly equal as []string (And so reflect.Type).
That said, personal considerations:
This solution is backward-compatible (in my opinion the most desired property).
(flagSet *FlagSet) Parse()
callsflagSet.CommandLine.Parse(os.Args[1:])
(ref: https://github.com/projectdiscovery/goflags/blob/main/goflags.go#L96) and it's not possible to override the second method. In that method the way used to set a flag value is to callSet()
and (as far as I know) there is no way to distinguish between user-inputted values and default ones. So there is no way to override the default value out of using theSet()
method.Each input flag should have the notion of default value, that's why I've thought to change StringSlice to a struct holding the Default indicator.
Maybe another solution could be also to change
optionMap
to be accessible from outside (OptionMap
) and insert the boolean value in that struct.TBH I don't have a clear abstract view of the code. I'm open to discuss, get suggestions and change completely the solution.
This PR closes #95.