Kongplete predictors and enums #314
-
Hi Alec, I am using an enum to specify what values should be allowed, and just started using Kongplete with custom predictions. Currently I repeat the enum values in the predictor's set, which is a bit of a chore, as they could get out of sync unintentionally. I was thinking - could we tie these together? Instead of hard-coding the enum values, perhaps we could let them get picked up from the predictor? Something like: var predictors = map[string]complete.Predictor{
"vals": complete.PredictSet("enum1", "enum2"),
}
type CLI struct {
Val string `name:"val" enum:"vals" predictor:"vals"`
}
func main() {
parser := kong.Must(&CLI, kong.WithEnumFromPredictors(predictors))
...
} In any case, it would be convenient to provide the enum values in a similar way to the predictors, where we can programmatically set the values of the enum. Something like: var enums = map[string][]strings{
"vals": []string{"enum1", "enum2"},
}
type CLI struct {
Val string `name:"val" enum:"vals"`
}
func main() {
parser := kong.Must(&CLI, kong.WithEnums(enums))
...
} Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I think it would be preferable if kongplete picked up the enum from Kong. |
Beta Was this translation helpful? Give feedback.
-
But as a workaround you could use |
Beta Was this translation helpful? Give feedback.
But as a workaround you could use
kong.Vars{}
to interpolate vars into the Kong tags.