fix(process): AX-6 banned-import purge in program.go (#299)
Replaced bytes/strings/unicode imports with core.NewBuffer, core.* helpers, and core.IsLetter / core.IsDigit. No banned imports remain. Closes tasks.lthn.sh/view.php?id=299 Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
parent
59ac2c5686
commit
0968d540b4
1 changed files with 19 additions and 8 deletions
27
program.go
27
program.go
|
|
@ -1,11 +1,8 @@
|
|||
package process
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
core "dappco.re/go/core"
|
||||
coreerr "dappco.re/go/log"
|
||||
|
|
@ -90,16 +87,30 @@ func (p *Program) RunDir(ctx context.Context, dir string, args ...string) (strin
|
|||
return "", coreerr.E("Program.RunDir", "program name is empty", ErrProgramNameRequired)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
out := core.NewBuffer()
|
||||
cmd := exec.CommandContext(ctx, binary, args...)
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &out
|
||||
cmd.Stdout = out
|
||||
cmd.Stderr = out
|
||||
if dir != "" {
|
||||
cmd.Dir = dir
|
||||
}
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return strings.TrimRightFunc(out.String(), unicode.IsSpace), coreerr.E("Program.RunDir", core.Sprintf("%q: command failed", p.Name), err)
|
||||
return trimRightSpace(out.String()), coreerr.E("Program.RunDir", core.Sprintf("%q: command failed", p.Name), err)
|
||||
}
|
||||
return strings.TrimRightFunc(out.String(), unicode.IsSpace), nil
|
||||
return trimRightSpace(out.String()), nil
|
||||
}
|
||||
|
||||
func trimRightSpace(s string) string {
|
||||
trimFrom := len(s)
|
||||
for i, r := range s {
|
||||
if core.IsSpace(r) {
|
||||
if trimFrom == len(s) {
|
||||
trimFrom = i
|
||||
}
|
||||
continue
|
||||
}
|
||||
trimFrom = len(s)
|
||||
}
|
||||
return s[:trimFrom]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue