Skip to content

Commit ff1c49f

Browse files
committed
refactor: better usage of bytes.Buffer type
1 parent 50f592c commit ff1c49f

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ func (e *Executor) runCommand(ctx context.Context, call Call, i int) error {
284284
return err
285285
}
286286
} else {
287-
buff := bytes.NewBuffer(nil)
288-
opts.Stdout = buff
287+
var stdout bytes.Buffer
288+
opts.Stdout = &stdout
289289
if err = execext.RunCommand(opts); err != nil {
290290
return err
291291
}
292-
os.Setenv(t.Set, strings.TrimSpace(buff.String()))
292+
os.Setenv(t.Set, strings.TrimSpace(stdout.String()))
293293
}
294294
return nil
295295
}

variable_handling.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
3232
return result, nil
3333
}
3434

35-
buff := bytes.NewBuffer(nil)
36-
35+
var stdout bytes.Buffer
3736
opts := &execext.RunCommandOptions{
3837
Command: strings.TrimPrefix(value, "$"),
3938
Dir: e.Dir,
40-
Stdout: buff,
39+
Stdout: &stdout,
4140
Stderr: e.Stderr,
4241
}
4342
if err := execext.RunCommand(opts); err != nil {
4443
return "", &dynamicVarError{cause: err, cmd: opts.Command}
4544
}
4645

47-
result := buff.String()
48-
result = strings.TrimSuffix(result, "\n")
46+
result := strings.TrimSuffix(stdout.String(), "\n")
4947
if strings.ContainsRune(result, '\n') {
5048
return "", ErrMultilineResultCmd
5149
}
@@ -140,8 +138,8 @@ func (e *Executor) ReplaceVariables(initial string, call Call) (string, error) {
140138
return "", err
141139
}
142140

143-
b := bytes.NewBuffer(nil)
144-
if err = templ.Execute(b, vars); err != nil {
141+
var b bytes.Buffer
142+
if err = templ.Execute(&b, vars); err != nil {
145143
return "", err
146144
}
147145
return b.String(), nil

0 commit comments

Comments
 (0)