mirror of
https://github.com/go-task/task.git
synced 2025-03-05 15:05:42 +02:00
refactor: better usage of bytes.Buffer type
This commit is contained in:
parent
50f592c540
commit
ff1c49f111
6
task.go
6
task.go
@ -284,12 +284,12 @@ func (e *Executor) runCommand(ctx context.Context, call Call, i int) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
buff := bytes.NewBuffer(nil)
|
||||
opts.Stdout = buff
|
||||
var stdout bytes.Buffer
|
||||
opts.Stdout = &stdout
|
||||
if err = execext.RunCommand(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
os.Setenv(t.Set, strings.TrimSpace(buff.String()))
|
||||
os.Setenv(t.Set, strings.TrimSpace(stdout.String()))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -32,20 +32,18 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
buff := bytes.NewBuffer(nil)
|
||||
|
||||
var stdout bytes.Buffer
|
||||
opts := &execext.RunCommandOptions{
|
||||
Command: strings.TrimPrefix(value, "$"),
|
||||
Dir: e.Dir,
|
||||
Stdout: buff,
|
||||
Stdout: &stdout,
|
||||
Stderr: e.Stderr,
|
||||
}
|
||||
if err := execext.RunCommand(opts); err != nil {
|
||||
return "", &dynamicVarError{cause: err, cmd: opts.Command}
|
||||
}
|
||||
|
||||
result := buff.String()
|
||||
result = strings.TrimSuffix(result, "\n")
|
||||
result := strings.TrimSuffix(stdout.String(), "\n")
|
||||
if strings.ContainsRune(result, '\n') {
|
||||
return "", ErrMultilineResultCmd
|
||||
}
|
||||
@ -140,8 +138,8 @@ func (e *Executor) ReplaceVariables(initial string, call Call) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
if err = templ.Execute(b, vars); err != nil {
|
||||
var b bytes.Buffer
|
||||
if err = templ.Execute(&b, vars); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return b.String(), nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user