diff --git a/contrib/tetragon-rthooks/go.mod b/contrib/tetragon-rthooks/go.mod index 4297809bae2..a5d7cc3acfa 100644 --- a/contrib/tetragon-rthooks/go.mod +++ b/contrib/tetragon-rthooks/go.mod @@ -6,7 +6,7 @@ go 1.23.0 toolchain go1.23.1 require ( - github.com/alecthomas/kong v1.3.0 + github.com/alecthomas/kong v1.4.0 github.com/cilium/lumberjack/v2 v2.4.0 github.com/cilium/tetragon/api v0.0.0-00010101000000-000000000000 github.com/containerd/containerd v1.7.23 diff --git a/contrib/tetragon-rthooks/go.sum b/contrib/tetragon-rthooks/go.sum index 7cc8e499aa0..797f0dc6933 100644 --- a/contrib/tetragon-rthooks/go.sum +++ b/contrib/tetragon-rthooks/go.sum @@ -7,8 +7,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/kong v1.3.0 h1:YJKuU6/TV2XOBtymafSeuzDvLAFR8cYMZiXVNLhAO6g= -github.com/alecthomas/kong v1.3.0/go.mod h1:IDc8HyiouDdpdiEiY81iaEJM8rSIW6LzX8On4FCO0bE= +github.com/alecthomas/kong v1.4.0 h1:UL7tzGMnnY0YRMMvJyITIRX1EpO6RbBRZDNcCevy3HA= +github.com/alecthomas/kong v1.4.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= diff --git a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/README.md b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/README.md index e3b9fe9cf69..5dbed024f37 100644 --- a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/README.md +++ b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/README.md @@ -663,8 +663,7 @@ func main() { ## Validation Kong does validation on the structure of a command-line, but also supports -extensible validation. Any node in the tree may implement the following -interface: +extensible validation. Any node in the tree may implement either of the following interfaces: ```go type Validatable interface { @@ -672,6 +671,12 @@ type Validatable interface { } ``` +```go +type Validatable interface { + Validate(kctx *kong.Context) error + } +``` + If one of these nodes is in the active command-line it will be called during normal validation. diff --git a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/callbacks.go b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/callbacks.go index c84f215c038..1df975d8236 100644 --- a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/callbacks.go +++ b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/callbacks.go @@ -81,7 +81,7 @@ func callFunction(f reflect.Value, bindings bindings) error { return err } ferr := out[0] - if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ferrv.IsNil() { + if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ((ferrv.Kind() == reflect.Interface || ferrv.Kind() == reflect.Pointer) && ferrv.IsNil()) { return nil } return ferr.(error) //nolint:forcetypeassert diff --git a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/context.go b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/context.go index 2ed5d28da52..8a8c2e1aa4f 100644 --- a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/context.go +++ b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/context.go @@ -208,7 +208,7 @@ func (c *Context) Validate() error { //nolint: gocyclo desc = node.Path() } if validate := isValidatable(value); validate != nil { - if err := validate.Validate(); err != nil { + if err := validate.Validate(c); err != nil { if desc != "" { return fmt.Errorf("%s: %w", desc, err) } @@ -809,18 +809,22 @@ func (c *Context) RunNode(node *Node, binds ...interface{}) (err error) { func (c *Context) Run(binds ...interface{}) (err error) { node := c.Selected() if node == nil { - if len(c.Path) > 0 { - selected := c.Path[0].Node() - if selected.Type == ApplicationNode { - method := getMethod(selected.Target, "Run") - if method.IsValid() { - return c.RunNode(selected, binds...) - } + if len(c.Path) == 0 { + return fmt.Errorf("no command selected") + } + selected := c.Path[0].Node() + if selected.Type == ApplicationNode { + method := getMethod(selected.Target, "Run") + if method.IsValid() { + node = selected } + } else { + return fmt.Errorf("no command selected") } - return fmt.Errorf("no command selected") } - return c.RunNode(node, binds...) + runErr := c.RunNode(node, binds...) + err = c.Kong.applyHook(c, "AfterRun") + return errors.Join(runErr, err) } // PrintUsage to Kong's stdout. @@ -996,7 +1000,7 @@ func checkEnum(value *Value, target reflect.Value) error { } enums = append(enums, fmt.Sprintf("%q", enum)) } - return fmt.Errorf("%s must be one of %s but got %q", value.ShortSummary(), strings.Join(enums, ","), target.Interface()) + return fmt.Errorf("%s must be one of %s but got %q", value.ShortSummary(), strings.Join(enums, ","), fmt.Sprintf("%v", target.Interface())) } } @@ -1094,12 +1098,23 @@ func findPotentialCandidates(needle string, haystack []string, format string, ar } type validatable interface{ Validate() error } +type extendedValidatable interface { + Validate(kctx *Context) error +} -func isValidatable(v reflect.Value) validatable { +// Proxy a validatable function to the extendedValidatable interface +type validatableFunc func() error + +func (f validatableFunc) Validate(kctx *Context) error { return f() } + +func isValidatable(v reflect.Value) extendedValidatable { if !v.IsValid() || (v.Kind() == reflect.Ptr || v.Kind() == reflect.Slice || v.Kind() == reflect.Map) && v.IsNil() { return nil } if validate, ok := v.Interface().(validatable); ok { + return validatableFunc(validate.Validate) + } + if validate, ok := v.Interface().(extendedValidatable); ok { return validate } if v.CanAddr() { diff --git a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/hooks.go b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/hooks.go index d166b08883a..9fdf24c1395 100644 --- a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/hooks.go +++ b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/hooks.go @@ -3,17 +3,24 @@ package kong // BeforeResolve is a documentation-only interface describing hooks that run before resolvers are applied. type BeforeResolve interface { // This is not the correct signature - see README for details. - BeforeResolve(args ...interface{}) error + BeforeResolve(args ...any) error } // BeforeApply is a documentation-only interface describing hooks that run before values are set. type BeforeApply interface { // This is not the correct signature - see README for details. - BeforeApply(args ...interface{}) error + BeforeApply(args ...any) error } // AfterApply is a documentation-only interface describing hooks that run after values are set. type AfterApply interface { // This is not the correct signature - see README for details. - AfterApply(args ...interface{}) error + AfterApply(args ...any) error +} + +// AfterRun is a documentation-only interface describing hooks that run after Run() returns. +type AfterRun interface { + // This is not the correct signature - see README for details. + // AfterRun is called after Run() returns. + AfterRun(args ...any) error } diff --git a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/kong.go b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/kong.go index 10235d0ff66..45479becf9b 100644 --- a/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/kong.go +++ b/contrib/tetragon-rthooks/vendor/github.com/alecthomas/kong/kong.go @@ -249,19 +249,19 @@ func (k *Kong) interpolateValue(value *Value, vars Vars) (err error) { return fmt.Errorf("enum for %s: %s", value.Summary(), err) } - updatedVars := map[string]string{ - "default": value.Default, - "enum": value.Enum, - } if value.Default, err = interpolate(value.Default, vars, nil); err != nil { return fmt.Errorf("default value for %s: %s", value.Summary(), err) } if value.Enum, err = interpolate(value.Enum, vars, nil); err != nil { return fmt.Errorf("enum value for %s: %s", value.Summary(), err) } + updatedVars := map[string]string{ + "default": value.Default, + "enum": value.Enum, + } if value.Flag != nil { for i, env := range value.Flag.Envs { - if value.Flag.Envs[i], err = interpolate(env, vars, nil); err != nil { + if value.Flag.Envs[i], err = interpolate(env, vars, updatedVars); err != nil { return fmt.Errorf("env value for %s: %s", value.Summary(), err) } } diff --git a/contrib/tetragon-rthooks/vendor/modules.txt b/contrib/tetragon-rthooks/vendor/modules.txt index 9d49642511a..d23b5957365 100644 --- a/contrib/tetragon-rthooks/vendor/modules.txt +++ b/contrib/tetragon-rthooks/vendor/modules.txt @@ -4,8 +4,8 @@ cel.dev/expr # dario.cat/mergo v1.0.0 ## explicit; go 1.13 dario.cat/mergo -# github.com/alecthomas/kong v1.3.0 -## explicit; go 1.18 +# github.com/alecthomas/kong v1.4.0 +## explicit; go 1.20 github.com/alecthomas/kong # github.com/antlr4-go/antlr/v4 v4.13.0 ## explicit; go 1.20 diff --git a/go.mod b/go.mod index 1841c6487a0..356767e0958 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ go 1.23.0 toolchain go1.23.1 require ( - github.com/alecthomas/kong v1.3.0 + github.com/alecthomas/kong v1.4.0 github.com/bombsimon/logrusr/v4 v4.1.0 github.com/cilium/cilium v1.17.0-pre.2 github.com/cilium/ebpf v0.16.0 diff --git a/go.sum b/go.sum index 72fba49241c..8520a746282 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0k github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/kong v1.3.0 h1:YJKuU6/TV2XOBtymafSeuzDvLAFR8cYMZiXVNLhAO6g= -github.com/alecthomas/kong v1.3.0/go.mod h1:IDc8HyiouDdpdiEiY81iaEJM8rSIW6LzX8On4FCO0bE= +github.com/alecthomas/kong v1.4.0 h1:UL7tzGMnnY0YRMMvJyITIRX1EpO6RbBRZDNcCevy3HA= +github.com/alecthomas/kong v1.4.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= diff --git a/vendor/github.com/alecthomas/kong/README.md b/vendor/github.com/alecthomas/kong/README.md index e3b9fe9cf69..5dbed024f37 100644 --- a/vendor/github.com/alecthomas/kong/README.md +++ b/vendor/github.com/alecthomas/kong/README.md @@ -663,8 +663,7 @@ func main() { ## Validation Kong does validation on the structure of a command-line, but also supports -extensible validation. Any node in the tree may implement the following -interface: +extensible validation. Any node in the tree may implement either of the following interfaces: ```go type Validatable interface { @@ -672,6 +671,12 @@ type Validatable interface { } ``` +```go +type Validatable interface { + Validate(kctx *kong.Context) error + } +``` + If one of these nodes is in the active command-line it will be called during normal validation. diff --git a/vendor/github.com/alecthomas/kong/callbacks.go b/vendor/github.com/alecthomas/kong/callbacks.go index c84f215c038..1df975d8236 100644 --- a/vendor/github.com/alecthomas/kong/callbacks.go +++ b/vendor/github.com/alecthomas/kong/callbacks.go @@ -81,7 +81,7 @@ func callFunction(f reflect.Value, bindings bindings) error { return err } ferr := out[0] - if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ferrv.IsNil() { + if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ((ferrv.Kind() == reflect.Interface || ferrv.Kind() == reflect.Pointer) && ferrv.IsNil()) { return nil } return ferr.(error) //nolint:forcetypeassert diff --git a/vendor/github.com/alecthomas/kong/context.go b/vendor/github.com/alecthomas/kong/context.go index 2ed5d28da52..8a8c2e1aa4f 100644 --- a/vendor/github.com/alecthomas/kong/context.go +++ b/vendor/github.com/alecthomas/kong/context.go @@ -208,7 +208,7 @@ func (c *Context) Validate() error { //nolint: gocyclo desc = node.Path() } if validate := isValidatable(value); validate != nil { - if err := validate.Validate(); err != nil { + if err := validate.Validate(c); err != nil { if desc != "" { return fmt.Errorf("%s: %w", desc, err) } @@ -809,18 +809,22 @@ func (c *Context) RunNode(node *Node, binds ...interface{}) (err error) { func (c *Context) Run(binds ...interface{}) (err error) { node := c.Selected() if node == nil { - if len(c.Path) > 0 { - selected := c.Path[0].Node() - if selected.Type == ApplicationNode { - method := getMethod(selected.Target, "Run") - if method.IsValid() { - return c.RunNode(selected, binds...) - } + if len(c.Path) == 0 { + return fmt.Errorf("no command selected") + } + selected := c.Path[0].Node() + if selected.Type == ApplicationNode { + method := getMethod(selected.Target, "Run") + if method.IsValid() { + node = selected } + } else { + return fmt.Errorf("no command selected") } - return fmt.Errorf("no command selected") } - return c.RunNode(node, binds...) + runErr := c.RunNode(node, binds...) + err = c.Kong.applyHook(c, "AfterRun") + return errors.Join(runErr, err) } // PrintUsage to Kong's stdout. @@ -996,7 +1000,7 @@ func checkEnum(value *Value, target reflect.Value) error { } enums = append(enums, fmt.Sprintf("%q", enum)) } - return fmt.Errorf("%s must be one of %s but got %q", value.ShortSummary(), strings.Join(enums, ","), target.Interface()) + return fmt.Errorf("%s must be one of %s but got %q", value.ShortSummary(), strings.Join(enums, ","), fmt.Sprintf("%v", target.Interface())) } } @@ -1094,12 +1098,23 @@ func findPotentialCandidates(needle string, haystack []string, format string, ar } type validatable interface{ Validate() error } +type extendedValidatable interface { + Validate(kctx *Context) error +} -func isValidatable(v reflect.Value) validatable { +// Proxy a validatable function to the extendedValidatable interface +type validatableFunc func() error + +func (f validatableFunc) Validate(kctx *Context) error { return f() } + +func isValidatable(v reflect.Value) extendedValidatable { if !v.IsValid() || (v.Kind() == reflect.Ptr || v.Kind() == reflect.Slice || v.Kind() == reflect.Map) && v.IsNil() { return nil } if validate, ok := v.Interface().(validatable); ok { + return validatableFunc(validate.Validate) + } + if validate, ok := v.Interface().(extendedValidatable); ok { return validate } if v.CanAddr() { diff --git a/vendor/github.com/alecthomas/kong/hooks.go b/vendor/github.com/alecthomas/kong/hooks.go index d166b08883a..9fdf24c1395 100644 --- a/vendor/github.com/alecthomas/kong/hooks.go +++ b/vendor/github.com/alecthomas/kong/hooks.go @@ -3,17 +3,24 @@ package kong // BeforeResolve is a documentation-only interface describing hooks that run before resolvers are applied. type BeforeResolve interface { // This is not the correct signature - see README for details. - BeforeResolve(args ...interface{}) error + BeforeResolve(args ...any) error } // BeforeApply is a documentation-only interface describing hooks that run before values are set. type BeforeApply interface { // This is not the correct signature - see README for details. - BeforeApply(args ...interface{}) error + BeforeApply(args ...any) error } // AfterApply is a documentation-only interface describing hooks that run after values are set. type AfterApply interface { // This is not the correct signature - see README for details. - AfterApply(args ...interface{}) error + AfterApply(args ...any) error +} + +// AfterRun is a documentation-only interface describing hooks that run after Run() returns. +type AfterRun interface { + // This is not the correct signature - see README for details. + // AfterRun is called after Run() returns. + AfterRun(args ...any) error } diff --git a/vendor/github.com/alecthomas/kong/kong.go b/vendor/github.com/alecthomas/kong/kong.go index 10235d0ff66..45479becf9b 100644 --- a/vendor/github.com/alecthomas/kong/kong.go +++ b/vendor/github.com/alecthomas/kong/kong.go @@ -249,19 +249,19 @@ func (k *Kong) interpolateValue(value *Value, vars Vars) (err error) { return fmt.Errorf("enum for %s: %s", value.Summary(), err) } - updatedVars := map[string]string{ - "default": value.Default, - "enum": value.Enum, - } if value.Default, err = interpolate(value.Default, vars, nil); err != nil { return fmt.Errorf("default value for %s: %s", value.Summary(), err) } if value.Enum, err = interpolate(value.Enum, vars, nil); err != nil { return fmt.Errorf("enum value for %s: %s", value.Summary(), err) } + updatedVars := map[string]string{ + "default": value.Default, + "enum": value.Enum, + } if value.Flag != nil { for i, env := range value.Flag.Envs { - if value.Flag.Envs[i], err = interpolate(env, vars, nil); err != nil { + if value.Flag.Envs[i], err = interpolate(env, vars, updatedVars); err != nil { return fmt.Errorf("env value for %s: %s", value.Summary(), err) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 9affe6e632b..b42bc9ce894 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -9,8 +9,8 @@ github.com/Microsoft/go-winio/internal/fs github.com/Microsoft/go-winio/internal/socket github.com/Microsoft/go-winio/internal/stringbuffer github.com/Microsoft/go-winio/pkg/guid -# github.com/alecthomas/kong v1.3.0 -## explicit; go 1.18 +# github.com/alecthomas/kong v1.4.0 +## explicit; go 1.20 github.com/alecthomas/kong # github.com/antlr4-go/antlr/v4 v4.13.0 ## explicit; go 1.20