New ๐ŸŒŠ wave for @helm

Commit a557fde6

a557fde63e5bMerged

Vigilans <[email protected]> ยท 11 months ago ยท 2 files ยท ~2 modified

Description

fix: golangci-lint issues

Signed-off-by: Vigilans [email protected]

Details

Commit
a557fde63e5b
Parent
86cd4a0c2421

pkg/template/extra.gomodifiedView file

@@ -68,6 +68,7 @@
6868 if errors.Is(err, io.EOF) {
6969 break
7070 }
71+
7172 return nil, fmt.Errorf("failed to unmarshal YAML document: %w", err)
7273 }
7374 if v != nil {
@@ -85,7 +86,9 @@
8586 // {{ exec "command arg1 arg2" }} - command string with arguments, split by shell-like rules
8687 // {{ exec "command" (list "arg1" "arg2") }} - command with explicit argument list
8788 // {{ "input" | exec "command arg1 arg2" }} - piped input with command string
88-// {{ "input" | exec "command" (list "arg1" "arg2") }} - piped input with explicit argument list
89+// {{ "input" | exec "command" (list "arg1" "arg2") }} - piped input with explicit argument list.
90+//
91+//nolint:gocognit,cyclop
8992 func Exec(command string, args ...any) (string, error) {
9093 var input string
9194 var strArgs []string
@@ -93,12 +96,10 @@
9396 switch len(args) {
9497 case 0: // {{ exec "command arg1 arg2" }}
9598 var err error
96- strArgs, err = parseCommandArgs(command)
99+ command, strArgs, err = parseCommandArgs(command)
97100 if err != nil {
98101 return "", err
99102 }
100- command = strArgs[0]
101- strArgs = strArgs[1:]
102103 case 1:
103104 switch v := args[0].(type) {
104105 case []any: // {{ exec "command" (list "arg1" "arg2") }}
@@ -110,20 +111,16 @@
110111 case string: // {{ "input" | exec "command arg1 arg2" }}
111112 input = v
112113 var err error
113- strArgs, err = parseCommandArgs(command)
114+ command, strArgs, err = parseCommandArgs(command)
114115 if err != nil {
115116 return "", err
116117 }
117- command = strArgs[0]
118- strArgs = strArgs[1:]
119118 case nil: // {{ exec "command arg1 arg2" }} with nil args
120119 var err error
121- strArgs, err = parseCommandArgs(command)
120+ command, strArgs, err = parseCommandArgs(command)
122121 if err != nil {
123122 return "", err
124123 }
125- command = strArgs[0]
126- strArgs = strArgs[1:]
127124 default:
128125 return "", fmt.Errorf("unexpected type of args[0]: %s", reflect.TypeOf(args[0]))
129126 }
@@ -181,19 +178,21 @@
181178 return nil, fmt.Errorf("unexpected type of arg \"%s\" in args %v at index %d", reflect.TypeOf(a), args, i)
182179 }
183180 }
181+
184182 return strArgs, nil
185183 }
186184
187185 // parseCommandArgs parses a command string into command and arguments.
188-func parseCommandArgs(command string) ([]string, error) {
186+func parseCommandArgs(command string) (string, []string, error) {
189187 result, err := shlex.Split(command)
190188 if err != nil {
191- return nil, fmt.Errorf("failed to parse command %q: %w", command, err)
189+ return "", nil, fmt.Errorf("failed to parse command %q: %w", command, err)
192190 }
193191 if len(result) == 0 {
194- result = []string{command}
192+ return command, []string{}, nil
195193 }
196- return result, nil
194+
195+ return result[0], result[1:], nil
197196 }
198197
199198 func writeCommandInput(stdin io.WriteCloser, input string, wg *parallel.WaitGroup) {
@@ -244,6 +243,7 @@
244243 } else {
245244 wg.ErrChan() <- fmt.Errorf("failed to run command: %w", err)
246245 }
246+
247247 return
248248 }
249249
@@ -255,6 +255,8 @@
255255
256256 // SetValueAtPath sets value in map by dot-separated key path.
257257 // Used as custom template function.
258+//
259+//nolint:gocognit,cyclop
258260 func SetValueAtPath(path string, value any, values Values) (Values, error) {
259261 var current any
260262 current = values