Files
QSfera/Server/vendor/github.com/gookit/goutil/sysutil/cmdr/cmdr.go
T
Курнат Андрей 2315f25754 Initial QSfera import
2026-06-07 10:20:04 +03:00

47 lines
914 B
Go

// Package cmdr Provide for quick build and run a cmd, batch run multi cmd tasks
package cmdr
import (
"strings"
"github.com/gookit/goutil/x/ccolor"
)
// PrintCmdline on before exec
func PrintCmdline(c *Cmd) {
if c.DryRun {
ccolor.Yellowln("DRY-RUN>", c.RawLine())
} else {
ccolor.Yellowln(">", c.RawLine())
}
}
// PrintCmdline2 on before exec
func PrintCmdline2(c *Cmd) {
if c.Dir != "" {
ccolor.Magentaln("> Workdir:", c.Dir)
}
if c.DryRun {
ccolor.Yellowln("DRY-RUN>", c.RawLine())
} else {
ccolor.Yellowln(">", c.RawLine())
}
}
// OutputLines split output to lines
func OutputLines(output string) []string {
output = strings.TrimSuffix(output, "\n")
if output == "" {
return nil
}
return strings.Split(output, "\n")
}
// FirstLine from command output
func FirstLine(output string) string {
if i := strings.Index(output, "\n"); i >= 0 {
return output[0:i]
}
return output
}