Skip to content

Commit

Permalink
util: move SplitNL() from cmd package to strs
Browse files Browse the repository at this point in the history
Signed-off-by: Enrico Weigelt, metux IT consult <[email protected]>
  • Loading branch information
metux committed Dec 10, 2023
1 parent 369e21d commit a57921d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 3 additions & 9 deletions util/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"os/exec"
"strings"

"github.com/metux/go-metabuild/util/strs"
)

func RunOut(cmdline []string, logErr bool) (string, error) {
Expand Down Expand Up @@ -42,22 +44,14 @@ func RunGroup(cmdlines [][]string) ([]string, []error) {
return outs, errs
}

func splitNL(s string) []string {
s = strings.TrimSpace(s)
if s == "" {
return []string{}
}
return strings.Split(s, "\n")
}

func RunOutOne(cmdline []string, logErr bool) (string, error) {
out, err := RunOut(cmdline, logErr)
return strings.TrimSpace(out), err
}

func RunOutLines(cmdline []string, logErr bool) ([]string, error) {
out, err := RunOutOne(cmdline, logErr)
return splitNL(out), err
return strs.SplitNL(out), err
}

func RunOutCmd(cmdline []string, logErr bool) ([]string, error) {
Expand Down
13 changes: 13 additions & 0 deletions util/strs/splitnl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package strs

import (
"strings"
)

func SplitNL(s string) []string {
s = strings.TrimSpace(s)
if s == "" {
return []string{}
}
return strings.Split(s, "\n")
}

0 comments on commit a57921d

Please sign in to comment.