diff --git a/contrib/rthooks/tetragon-oci-hook/go.mod b/contrib/rthooks/tetragon-oci-hook/go.mod index 722ca8689c5..a4c51bee6fc 100644 --- a/contrib/rthooks/tetragon-oci-hook/go.mod +++ b/contrib/rthooks/tetragon-oci-hook/go.mod @@ -4,7 +4,7 @@ module github.com/cilium/tetragon/contrib/rthooks/tetragon-oci-hook go 1.22.0 require ( - github.com/alecthomas/kong v0.8.1 + github.com/alecthomas/kong v0.9.0 github.com/cilium/lumberjack/v2 v2.3.0 github.com/cilium/tetragon/api v0.0.0-00010101000000-000000000000 github.com/containers/common v0.57.4 diff --git a/contrib/rthooks/tetragon-oci-hook/go.sum b/contrib/rthooks/tetragon-oci-hook/go.sum index a7d77cf2305..424b40e6620 100644 --- a/contrib/rthooks/tetragon-oci-hook/go.sum +++ b/contrib/rthooks/tetragon-oci-hook/go.sum @@ -1,12 +1,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= -github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA= -github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY= -github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= -github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= -github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= +github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= +github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA= +github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os= +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= github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/cilium/ebpf v0.12.3 h1:8ht6F9MquybnY97at+VDZb3eQQr8ev79RueWeVaEcG4= diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.gitignore b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.gitignore index ba077a4031a..e69de29bb2d 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.gitignore +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.gitignore @@ -1 +0,0 @@ -bin diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.golangci.yml b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.golangci.yml index 1ee8fa6f542..e8980bfcf8d 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.golangci.yml +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/.golangci.yml @@ -41,10 +41,21 @@ linters: - exhaustruct - nonamedreturns - nilnil + - nosnakecase # deprecated since v1.48.1 + - structcheck # deprecated since v1.49.0 + - deadcode # deprecated since v1.49.0 + - varcheck # deprecated since v1.49.0 + - depguard # nothing to guard against yet + - tagalign # hurts readability of kong tags linters-settings: govet: check-shadowing: true + # These govet checks are disabled by default, but they're useful. + enable: + - niliness + - sortslice + - unusedwrite dupl: threshold: 100 gocyclo: @@ -65,4 +76,14 @@ issues: - 'bad syntax for struct tag key' - 'bad syntax for struct tag pair' - 'result .* \(error\) is always nil' - - 'package io/ioutil is deprecated' + + exclude-rules: + # Don't warn on unused parameters. + # Parameter names are useful for documentation. + # Replacing them with '_' hides useful information. + - linters: [revive] + text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _' + + # Duplicate words are okay in tests. + - linters: [dupword] + path: _test\.go diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/README.md b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/README.md index 4110465a622..22e00f067a4 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/README.md +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/README.md @@ -330,7 +330,7 @@ var cli struct { func main() { // Debug logger going to discard. - logger := log.New(ioutil.Discard, "", log.LstdFlags) + logger := log.New(io.Discard, "", log.LstdFlags) ctx := kong.Parse(&cli, kong.Bind(logger)) @@ -566,7 +566,7 @@ Both can coexist with standard Tag parsing. | `default:"1"` | On a command, make it the default. | | `default:"withargs"` | On a command, make it the default and allow args/flags from that command | | `short:"X"` | Short name, if flag. | -| `aliases:"X,Y"` | One or more aliases (for cmd). | +| `aliases:"X,Y"` | One or more aliases (for cmd or flag). | | `required:""` | If present, flag/arg is required. | | `optional:""` | If present, flag/arg is optional. | | `hidden:""` | If present, command or flag is hidden. | diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/build.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/build.go index e23c11518ec..a52d90fa952 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/build.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/build.go @@ -296,6 +296,13 @@ func buildField(k *Kong, node *Node, v reflect.Value, ft reflect.StructField, fv return failField(v, ft, "duplicate flag --%s", value.Name) } seenFlags["--"+value.Name] = true + for _, alias := range tag.Aliases { + aliasFlag := "--" + alias + if seenFlags[aliasFlag] { + return failField(v, ft, "duplicate flag %s", aliasFlag) + } + seenFlags[aliasFlag] = true + } if tag.Short != 0 { if seenFlags["-"+string(tag.Short)] { return failField(v, ft, "duplicate short flag -%c", tag.Short) @@ -304,6 +311,7 @@ func buildField(k *Kong, node *Node, v reflect.Value, ft reflect.StructField, fv } flag := &Flag{ Value: value, + Aliases: tag.Aliases, Short: tag.Short, PlaceHolder: tag.PlaceHolder, Envs: tag.Envs, diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/callbacks.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/callbacks.go index 8771a3ecba9..45ef0d25f44 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/callbacks.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/callbacks.go @@ -41,7 +41,7 @@ func (b bindings) addProvider(provider interface{}) error { errv := out[1] var err error if !errv.IsNil() { - err = errv.Interface().(error) // nolint + err = errv.Interface().(error) //nolint } return out[0], err } @@ -99,7 +99,7 @@ func callFunction(f reflect.Value, bindings bindings) error { if out[0].IsNil() { return nil } - return out[0].Interface().(error) // nolint + return out[0].Interface().(error) //nolint } func callAnyFunction(f reflect.Value, bindings bindings) (out []any, err error) { diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/camelcase.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/camelcase.go index acf29f75770..a955b16ba21 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/camelcase.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/camelcase.go @@ -13,37 +13,37 @@ import ( // // Examples // -// "" => [""] -// "lowercase" => ["lowercase"] -// "Class" => ["Class"] -// "MyClass" => ["My", "Class"] -// "MyC" => ["My", "C"] -// "HTML" => ["HTML"] -// "PDFLoader" => ["PDF", "Loader"] -// "AString" => ["A", "String"] -// "SimpleXMLParser" => ["Simple", "XML", "Parser"] -// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] -// "GL11Version" => ["GL", "11", "Version"] -// "99Bottles" => ["99", "Bottles"] -// "May5" => ["May", "5"] -// "BFG9000" => ["BFG", "9000"] -// "BöseÜberraschung" => ["Böse", "Überraschung"] -// "Two spaces" => ["Two", " ", "spaces"] -// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] +// "" => [""] +// "lowercase" => ["lowercase"] +// "Class" => ["Class"] +// "MyClass" => ["My", "Class"] +// "MyC" => ["My", "C"] +// "HTML" => ["HTML"] +// "PDFLoader" => ["PDF", "Loader"] +// "AString" => ["A", "String"] +// "SimpleXMLParser" => ["Simple", "XML", "Parser"] +// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] +// "GL11Version" => ["GL", "11", "Version"] +// "99Bottles" => ["99", "Bottles"] +// "May5" => ["May", "5"] +// "BFG9000" => ["BFG", "9000"] +// "BöseÜberraschung" => ["Böse", "Überraschung"] +// "Two spaces" => ["Two", " ", "spaces"] +// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] // // Splitting rules // -// 1) If string is not valid UTF-8, return it without splitting as +// 1. If string is not valid UTF-8, return it without splitting as // single item array. -// 2) Assign all unicode characters into one of 4 sets: lower case +// 2. Assign all unicode characters into one of 4 sets: lower case // letters, upper case letters, numbers, and all other characters. -// 3) Iterate through characters of string, introducing splits +// 3. Iterate through characters of string, introducing splits // between adjacent characters that belong to different sets. -// 4) Iterate through array of split strings, and if a given string +// 4. Iterate through array of split strings, and if a given string // is upper case: -// if subsequent string is lower case: -// move last character of upper case string to beginning of -// lower case string +// if subsequent string is lower case: +// move last character of upper case string to beginning of +// lower case string func camelCase(src string) (entries []string) { // don't split invalid utf8 if !utf8.ValidString(src) { diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/context.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/context.go index 0b41079fa3a..b2bfea6933d 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/context.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/context.go @@ -161,7 +161,7 @@ func (c *Context) Empty() bool { } // Validate the current context. -func (c *Context) Validate() error { // nolint: gocyclo +func (c *Context) Validate() error { //nolint: gocyclo err := Visit(c.Model, func(node Visitable, next Next) error { switch node := node.(type) { case *Value: @@ -347,7 +347,7 @@ func (c *Context) endParsing() { } } -func (c *Context) trace(node *Node) (err error) { // nolint: gocyclo +func (c *Context) trace(node *Node) (err error) { //nolint: gocyclo positional := 0 node.Active = true @@ -377,7 +377,7 @@ func (c *Context) trace(node *Node) (err error) { // nolint: gocyclo switch { case v == "-": fallthrough - default: // nolint + default: //nolint c.scan.Pop() c.scan.PushTyped(token.Value, PositionalArgumentToken) @@ -684,15 +684,24 @@ func flipBoolValue(value reflect.Value) error { func (c *Context) parseFlag(flags []*Flag, match string) (err error) { candidates := []string{} + for _, flag := range flags { long := "--" + flag.Name - short := "-" + string(flag.Short) - neg := "--no-" + flag.Name + matched := long == match candidates = append(candidates, long) if flag.Short != 0 { + short := "-" + string(flag.Short) + matched = matched || (short == match) candidates = append(candidates, short) } - if short != match && long != match && !(match == neg && flag.Tag.Negatable) { + for _, alias := range flag.Aliases { + alias = "--" + alias + matched = matched || (alias == match) + candidates = append(candidates, alias) + } + + neg := "--no-" + flag.Name + if !matched && !(match == neg && flag.Tag.Negatable) { continue } // Found a matching flag. diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/doc.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/doc.go index 78c4d11037b..7e53da7f362 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/doc.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/doc.go @@ -2,31 +2,31 @@ // // Here's an example: // -// shell rm [-f] [-r] ... -// shell ls [ ...] +// shell rm [-f] [-r] ... +// shell ls [ ...] // // This can be represented by the following command-line structure: // -// package main +// package main // -// import "github.com/alecthomas/kong" +// import "github.com/alecthomas/kong" // -// var CLI struct { -// Rm struct { -// Force bool `short:"f" help:"Force removal."` -// Recursive bool `short:"r" help:"Recursively remove files."` +// var CLI struct { +// Rm struct { +// Force bool `short:"f" help:"Force removal."` +// Recursive bool `short:"r" help:"Recursively remove files."` // -// Paths []string `arg help:"Paths to remove." type:"path"` -// } `cmd help:"Remove files."` +// Paths []string `arg help:"Paths to remove." type:"path"` +// } `cmd help:"Remove files."` // -// Ls struct { -// Paths []string `arg optional help:"Paths to list." type:"path"` -// } `cmd help:"List paths."` -// } +// Ls struct { +// Paths []string `arg optional help:"Paths to list." type:"path"` +// } `cmd help:"List paths."` +// } // -// func main() { -// kong.Parse(&CLI) -// } +// func main() { +// kong.Parse(&CLI) +// } // // See https://github.com/alecthomas/kong for details. package kong diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth.go index 46768e68301..dfdc3f5134b 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth.go @@ -1,3 +1,4 @@ +//go:build appengine || (!linux && !freebsd && !darwin && !dragonfly && !netbsd && !openbsd) // +build appengine !linux,!freebsd,!darwin,!dragonfly,!netbsd,!openbsd package kong diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth_unix.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth_unix.go index db52595e248..0170055a79c 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth_unix.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/guesswidth_unix.go @@ -27,9 +27,9 @@ func guessWidth(w io.Writer) int { if _, _, err := syscall.Syscall6( syscall.SYS_IOCTL, - uintptr(fd), // nolint: unconvert + uintptr(fd), //nolint: unconvert uintptr(syscall.TIOCGWINSZ), - uintptr(unsafe.Pointer(&dimensions)), // nolint: gas + uintptr(unsafe.Pointer(&dimensions)), //nolint: gas 0, 0, 0, ); err == 0 { if dimensions[1] == 0 { diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/help.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/help.go index 4fb77001d4c..cf5a912c2e9 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/help.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/help.go @@ -490,6 +490,7 @@ func formatFlag(haveShort bool, flag *Flag) string { flagString := "" name := flag.Name isBool := flag.IsBool() + isCounter := flag.IsCounter() if flag.Short != 0 { if isBool && flag.Tag.Negatable { flagString += fmt.Sprintf("-%c, --[no-]%s", flag.Short, name) @@ -511,7 +512,7 @@ func formatFlag(haveShort bool, flag *Flag) string { } } } - if !isBool { + if !isBool && !isCounter { flagString += fmt.Sprintf("=%s", flag.FormatPlaceHolder()) } return flagString diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/kong.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/kong.go index c4eda712a6a..76eaefe7011 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/kong.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/kong.go @@ -412,7 +412,7 @@ func (k *Kong) FatalIfErrorf(err error, args ...interface{}) { } msg := err.Error() if len(args) > 0 { - msg = fmt.Sprintf(args[0].(string), args[1:]...) + ": " + err.Error() // nolint + msg = fmt.Sprintf(args[0].(string), args[1:]...) + ": " + err.Error() //nolint } // Maybe display usage information. var parseErr *ParseError @@ -439,11 +439,11 @@ func (k *Kong) LoadConfig(path string) (Resolver, error) { if err != nil { return nil, err } - r, err := os.Open(path) // nolint: gas + r, err := os.Open(path) //nolint: gas if err != nil { return nil, err } - defer r.Close() // nolint: gosec + defer r.Close() return k.loader(r) } diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/mapper.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/mapper.go index c332cce4562..584bb00691d 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/mapper.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/mapper.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "math/bits" "net/url" "os" @@ -59,9 +59,9 @@ type mapperValueAdapter struct { func (m *mapperValueAdapter) Decode(ctx *DecodeContext, target reflect.Value) error { if target.Type().Implements(mapperValueType) { - return target.Interface().(MapperValue).Decode(ctx) // nolint + return target.Interface().(MapperValue).Decode(ctx) //nolint } - return target.Addr().Interface().(MapperValue).Decode(ctx) // nolint + return target.Addr().Interface().(MapperValue).Decode(ctx) //nolint } func (m *mapperValueAdapter) IsBool() bool { @@ -77,9 +77,9 @@ func (m *textUnmarshalerAdapter) Decode(ctx *DecodeContext, target reflect.Value return err } if target.Type().Implements(textUnmarshalerType) { - return target.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(value)) // nolint + return target.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(value)) //nolint } - return target.Addr().Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(value)) // nolint + return target.Addr().Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(value)) //nolint } type binaryUnmarshalerAdapter struct{} @@ -91,9 +91,9 @@ func (m *binaryUnmarshalerAdapter) Decode(ctx *DecodeContext, target reflect.Val return err } if target.Type().Implements(binaryUnmarshalerType) { - return target.Interface().(encoding.BinaryUnmarshaler).UnmarshalBinary([]byte(value)) // nolint + return target.Interface().(encoding.BinaryUnmarshaler).UnmarshalBinary([]byte(value)) //nolint } - return target.Addr().Interface().(encoding.BinaryUnmarshaler).UnmarshalBinary([]byte(value)) // nolint + return target.Addr().Interface().(encoding.BinaryUnmarshaler).UnmarshalBinary([]byte(value)) //nolint } type jsonUnmarshalerAdapter struct{} @@ -105,9 +105,9 @@ func (j *jsonUnmarshalerAdapter) Decode(ctx *DecodeContext, target reflect.Value return err } if target.Type().Implements(jsonUnmarshalerType) { - return target.Interface().(json.Unmarshaler).UnmarshalJSON([]byte(value)) // nolint + return target.Interface().(json.Unmarshaler).UnmarshalJSON([]byte(value)) //nolint } - return target.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(value)) // nolint + return target.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(value)) //nolint } // A Mapper represents how a field is mapped from command-line values to Go. @@ -142,7 +142,7 @@ type BoolMapperExt interface { // A MapperFunc is a single function that complies with the Mapper interface. type MapperFunc func(ctx *DecodeContext, target reflect.Value) error -func (m MapperFunc) Decode(ctx *DecodeContext, target reflect.Value) error { // nolint: revive +func (m MapperFunc) Decode(ctx *DecodeContext, target reflect.Value) error { //nolint: revive return m(ctx, target) } @@ -339,7 +339,7 @@ func durationDecoder() MapperFunc { return fmt.Errorf("expected duration but got %q: %v", v, err) } case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: - d = reflect.ValueOf(v).Convert(reflect.TypeOf(time.Duration(0))).Interface().(time.Duration) // nolint: forcetypeassert + d = reflect.ValueOf(v).Convert(reflect.TypeOf(time.Duration(0))).Interface().(time.Duration) //nolint: forcetypeassert default: return fmt.Errorf("expected duration but got %q", v) } @@ -367,7 +367,7 @@ func timeDecoder() MapperFunc { } } -func intDecoder(bits int) MapperFunc { // nolint: dupl +func intDecoder(bits int) MapperFunc { //nolint: dupl return func(ctx *DecodeContext, target reflect.Value) error { t, err := ctx.Scan.PopValue("int") if err != nil { @@ -396,7 +396,7 @@ func intDecoder(bits int) MapperFunc { // nolint: dupl } } -func uintDecoder(bits int) MapperFunc { // nolint: dupl +func uintDecoder(bits int) MapperFunc { //nolint: dupl return func(ctx *DecodeContext, target reflect.Value) error { t, err := ctx.Scan.PopValue("uint") if err != nil { @@ -540,7 +540,7 @@ func sliceDecoder(r *Registry) MapperFunc { var childScanner *Scanner if ctx.Value.Flag != nil { t := ctx.Scan.Pop() - // If decoding a flag, we need an value. + // If decoding a flag, we need a value. if t.IsEOL() { return fmt.Errorf("missing value, expecting \"%c...\"", sep) } @@ -580,6 +580,12 @@ func pathMapper(r *Registry) MapperFunc { if target.Kind() == reflect.Slice { return sliceDecoder(r)(ctx, target) } + if target.Kind() == reflect.Ptr && target.Elem().Kind() == reflect.String { + if target.IsNil() { + return nil + } + target = target.Elem() + } if target.Kind() != reflect.String { return fmt.Errorf("\"path\" type must be applied to a string not %s", target.Type()) } @@ -611,7 +617,7 @@ func fileMapper(r *Registry) MapperFunc { file = os.Stdin } else { path = ExpandPath(path) - file, err = os.Open(path) // nolint: gosec + file, err = os.Open(path) //nolint: gosec if err != nil { return err } @@ -635,7 +641,7 @@ func existingFileMapper(r *Registry) MapperFunc { return err } - if !ctx.Value.Active || ctx.Value.Set { + if !ctx.Value.Active || (ctx.Value.Set && ctx.Value.Target.Type() == target.Type()) { // early return to avoid checking extra files that may not exist; // this hack only works because the value provided on the cli is // checked before the default value is checked (if default is set). @@ -671,7 +677,7 @@ func existingDirMapper(r *Registry) MapperFunc { return err } - if !ctx.Value.Active || ctx.Value.Set { + if !ctx.Value.Active || (ctx.Value.Set && ctx.Value.Target.Type() == target.Type()) { // early return to avoid checking extra dirs that may not exist; // this hack only works because the value provided on the cli is // checked before the default value is checked (if default is set). @@ -712,11 +718,14 @@ func fileContentMapper(r *Registry) MapperFunc { var data []byte if path != "-" { path = ExpandPath(path) - data, err = ioutil.ReadFile(path) //nolint:gosec + data, err = os.ReadFile(path) //nolint:gosec } else { - data, err = ioutil.ReadAll(os.Stdin) + data, err = io.ReadAll(os.Stdin) } if err != nil { + if info, statErr := os.Stat(path); statErr == nil && info.IsDir() { + return fmt.Errorf("%q exists but is a directory: %w", path, err) + } return err } target.SetBytes(data) @@ -869,7 +878,7 @@ type NamedFileContentFlag struct { Contents []byte } -func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: revive +func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { //nolint: revive var filename string err := ctx.Scan.PopValueInto("filename", &filename) if err != nil { @@ -881,7 +890,7 @@ func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: rev return nil } filename = ExpandPath(filename) - data, err := ioutil.ReadFile(filename) // nolint: gosec + data, err := os.ReadFile(filename) //nolint: gosec if err != nil { return fmt.Errorf("failed to open %q: %v", filename, err) } @@ -893,7 +902,7 @@ func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: rev // FileContentFlag is a flag value that loads a file's contents into its value. type FileContentFlag []byte -func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: revive +func (f *FileContentFlag) Decode(ctx *DecodeContext) error { //nolint: revive var filename string err := ctx.Scan.PopValueInto("filename", &filename) if err != nil { @@ -905,7 +914,7 @@ func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: revive return nil } filename = ExpandPath(filename) - data, err := ioutil.ReadFile(filename) // nolint: gosec + data, err := os.ReadFile(filename) //nolint: gosec if err != nil { return fmt.Errorf("failed to open %q: %v", filename, err) } diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/model.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/model.go index 793cf97bcce..8d1f82f9a0a 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/model.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/model.go @@ -162,6 +162,16 @@ func (n *Node) Summary() string { } else if len(n.Children) > 0 { summary += " " } + allFlags := n.Flags + if n.Parent != nil { + allFlags = append(allFlags, n.Parent.Flags...) + } + for _, flag := range allFlags { + if !flag.Required { + summary += " [flags]" + break + } + } return summary } @@ -368,9 +378,9 @@ func (v *Value) Reset() error { v.Target.Set(reflect.Zero(v.Target.Type())) if len(v.Tag.Envs) != 0 { for _, env := range v.Tag.Envs { - envar := os.Getenv(env) + envar, ok := os.LookupEnv(env) // Parse the first non-empty ENV in the list - if envar != "" { + if ok { err := v.Parse(ScanFromTokens(Token{Type: FlagValueToken, Value: envar}), v.Target) if err != nil { return fmt.Errorf("%s (from envar %s=%q)", err, env, envar) @@ -397,6 +407,7 @@ type Flag struct { Xor []string PlaceHolder string Envs []string + Aliases []string Short rune Hidden bool Negated bool @@ -490,6 +501,9 @@ func reflectValueIsZero(v reflect.Value) bool { default: // This should never happens, but will act as a safeguard for // later, as a default value doesn't makes sense here. - panic(&reflect.ValueError{"reflect.Value.IsZero", v.Kind()}) + panic(&reflect.ValueError{ + Method: "reflect.Value.IsZero", + Kind: v.Kind(), + }) } } diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/options.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/options.go index 8d2893cf143..d01aeec22c4 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/options.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/options.go @@ -20,7 +20,7 @@ type Option interface { // OptionFunc is function that adheres to the Option interface. type OptionFunc func(k *Kong) error -func (o OptionFunc) Apply(k *Kong) error { return o(k) } // nolint: revive +func (o OptionFunc) Apply(k *Kong) error { return o(k) } //nolint: revive // Vars sets the variables to use for interpolation into help strings and default values. // @@ -287,7 +287,7 @@ func AutoGroup(format func(parent Visitable, flag *Flag) *Group) Option { // See also ExplicitGroups for a more structured alternative. type Groups map[string]string -func (g Groups) Apply(k *Kong) error { // nolint: revive +func (g Groups) Apply(k *Kong) error { //nolint: revive for key, info := range g { lines := strings.Split(info, "\n") title := strings.TrimSpace(lines[0]) diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/renovate.json5 b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/renovate.json5 new file mode 100644 index 00000000000..561d59fd876 --- /dev/null +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/renovate.json5 @@ -0,0 +1,18 @@ +{ + $schema: "https://docs.renovatebot.com/renovate-schema.json", + extends: [ + "config:recommended", + ":semanticCommits", + ":semanticCommitTypeAll(chore)", + ":semanticCommitScope(deps)", + "group:allNonMajor", + "schedule:earlyMondays", // Run once a week. + ], + packageRules: [ + { + "matchPackageNames": ["golangci-lint"], + "matchManagers": ["hermit"], + "enabled": false + }, + ] +} diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/resolver.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/resolver.go index ac1de1fccd1..05be7f681aa 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/resolver.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/resolver.go @@ -22,10 +22,10 @@ type ResolverFunc func(context *Context, parent *Path, flag *Flag) (interface{}, var _ Resolver = ResolverFunc(nil) -func (r ResolverFunc) Resolve(context *Context, parent *Path, flag *Flag) (interface{}, error) { // nolint: revive +func (r ResolverFunc) Resolve(context *Context, parent *Path, flag *Flag) (interface{}, error) { //nolint: revive return r(context, parent, flag) } -func (r ResolverFunc) Validate(app *Application) error { return nil } // nolint: revive +func (r ResolverFunc) Validate(app *Application) error { return nil } //nolint: revive // JSON returns a Resolver that retrieves values from a JSON source. // diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/scanner.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/scanner.go index 1766c4b20d2..c8a8bd60dbb 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/scanner.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/scanner.go @@ -82,7 +82,7 @@ func (t Token) InferredType() TokenType { return t.Type } if v, ok := t.Value.(string); ok { - if strings.HasPrefix(v, "--") { // nolint: gocritic + if strings.HasPrefix(v, "--") { //nolint: gocritic return FlagToken } else if v == "-" { return PositionalArgumentToken @@ -109,7 +109,7 @@ func (t Token) IsValue() bool { // // For example, the token "--foo=bar" will be split into the following by the parser: // -// [{FlagToken, "foo"}, {FlagValueToken, "bar"}] +// [{FlagToken, "foo"}, {FlagValueToken, "bar"}] type Scanner struct { args []Token } diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/tag.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/tag.go index f99059beab9..3e37c194908 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/tag.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/tag.go @@ -62,7 +62,7 @@ type tagChars struct { var kongChars = tagChars{sep: ',', quote: '\'', assign: '=', needsUnquote: false} var bareChars = tagChars{sep: ' ', quote: '"', assign: ':', needsUnquote: true} -// nolint:gocyclo +//nolint:gocyclo func parseTagItems(tagString string, chr tagChars) (map[string][]string, error) { d := map[string][]string{} key := []rune{} @@ -203,7 +203,7 @@ func parseTag(parent reflect.Value, ft reflect.StructField) (*Tag, error) { return t, nil } -func hydrateTag(t *Tag, typ reflect.Type) error { // nolint: gocyclo +func hydrateTag(t *Tag, typ reflect.Type) error { //nolint: gocyclo var typeName string var isBool bool var isBoolPtr bool diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/util.go b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/util.go index 50b1dfef786..8b7066429b8 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/util.go +++ b/contrib/rthooks/tetragon-oci-hook/vendor/github.com/alecthomas/kong/util.go @@ -17,7 +17,7 @@ func (c ConfigFlag) BeforeResolve(kong *Kong, ctx *Context, trace *Path) error { if kong.loader == nil { return fmt.Errorf("kong must be configured with kong.Configuration(...)") } - path := string(ctx.FlagValue(trace.Flag).(ConfigFlag)) // nolint + path := string(ctx.FlagValue(trace.Flag).(ConfigFlag)) //nolint resolver, err := kong.LoadConfig(path) if err != nil { return err diff --git a/contrib/rthooks/tetragon-oci-hook/vendor/modules.txt b/contrib/rthooks/tetragon-oci-hook/vendor/modules.txt index caeda5f76ab..be57534ba85 100644 --- a/contrib/rthooks/tetragon-oci-hook/vendor/modules.txt +++ b/contrib/rthooks/tetragon-oci-hook/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/alecthomas/kong v0.8.1 +# github.com/alecthomas/kong v0.9.0 ## explicit; go 1.18 github.com/alecthomas/kong # github.com/antlr4-go/antlr/v4 v4.13.0