feat: allow non-structs to be used as commands (#428)

* feat: allow non-structs to be used as commands

This small MR allows using the func-to-interface trick to implement a command (see commandFunc in kong_test.go).

This is useful e.g. for commands that have no flags or arguments of their own, but instead receive all required information via bound  parameters.

* fix: check DynamicCommand is runnable when adding
This commit is contained in:
Leo Antunes
2024-07-05 14:51:38 +02:00
committed by GitHub
parent 605cdd64a9
commit e864bb0220
4 changed files with 25 additions and 2 deletions
+3
View File
@@ -51,6 +51,9 @@ type flattenedField struct {
func flattenedFields(v reflect.Value, ptag *Tag) (out []flattenedField, err error) {
v = reflect.Indirect(v)
if v.Kind() != reflect.Struct {
return out, nil
}
for i := 0; i < v.NumField(); i++ {
ft := v.Type().Field(i)
fv := v.Field(i)