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

Fix EnumVarP func to show default value associated with EnumVariable … #106

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

RamanaReddy0M
Copy link
Contributor

…(#104)

Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggesting stricter check on enum values

goflags.go Show resolved Hide resolved
@tarunKoyalwar
Copy link
Member

@Mzack9999 , what do you thing about changing default value type and AllowedTypes?

Current Implementation

flagSet.EnumVarP(&options.ScanStrategy, "scan-strategy", "ss", goflags.EnumVariable(0), "strategy to use while scanning(auto/host-spray/template-spray)", goflags.AllowdTypes{
			"auto":           goflags.EnumVariable(0),
			"host-spray":     goflags.EnumVariable(1),
			"template-spray": goflags.EnumVariable(2),
		})

New Implementation

flagSet.EnumVarP(&options.ScanStrategy, "scan-strategy", "ss", "auto", "strategy to use while scanning(auto/host-spray/template-spray)", []string{"auto","host-spray","template-spray"}

we will use Allowd Types internally but there doesn't seem a need to expose it and make it complex .
and for validation we can simply do

if _,ok:= AllowedTypes[defaultValue]; !ok{
    panic(fmt.Errof("%v does not belong to %v",defaultValue,AllowedTypes))
}

@Mzack9999 Mzack9999 self-requested a review February 16, 2023 08:25
@Mzack9999
Copy link
Member

@tarunKoyalwar That's what I was discussing with @RamanaReddy0M , I think anyway that a iota allows to plug in more generic implementations. Internally it's needed some refactoring as also other types like boolean/ints are considered like strings, losing their original type

@Mzack9999 Mzack9999 merged commit 24e2560 into main Feb 16, 2023
@Mzack9999 Mzack9999 deleted the issue-104-enum-var branch February 16, 2023 09:00
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.

Enum type variables prints 0 instead of default value in help
3 participants