[Agent] [Executor] 完成PipelineCommand part

This commit is contained in:
zeaslity
2023-10-18 10:39:38 +08:00
parent be01eb28a9
commit f31b303ff8
4 changed files with 151 additions and 25 deletions

View File

@@ -1,8 +1,10 @@
package executor
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
var RemoveForcePrefix = []string{"rm", "-rf"}
@@ -81,3 +83,37 @@ func BasicPrettyPrint(resultOk bool, resultLog []string) {
fmt.Println(s)
}
}
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
var pipelineCommandC [][]string
split := strings.Split(pipelineString, "|")
if len(split) == 0 {
log.WarnF("输入的pipelineString有误 %s", pipelineString)
return pipelineCommandC
}
for _, s := range split {
// 去除掉无效的空行
singleCommand := strings.Split(s, " ")
var realSingleCommand []string
for i := range singleCommand {
if singleCommand[i] != "" {
realSingleCommand = append(realSingleCommand, singleCommand[i])
}
}
pipelineCommandC = append(pipelineCommandC, realSingleCommand)
}
return pipelineCommandC
}
func BasicConvertBufferToSlice(outputBuffer bytes.Buffer) (resultLog []string) {
s := outputBuffer.String()
split := strings.Split(s, "\n")
return split
}