MCPcopy Create free account
hub / github.com/dim-an/cod / ParseSimpleCommand

Function ParseSimpleCommand

shells/parse.go:33–61  ·  view source on GitHub ↗
(cmd string)

Source from the content-addressed store, hash-verified

31}
32
33func ParseSimpleCommand(cmd string) (env, args []string, err error) {
34 tokens, err := Tokenize(cmd)
35 if err != nil {
36 return
37 }
38
39 for _, t := range tokens {
40 if t.IsScary {
41 err = errCommandNotSimple("command is not simple", cmd)
42 args = nil
43 env = nil
44 return
45 }
46 if isVariableAssignment(t.Decoded) && len(args) == 0 {
47 env = append(env, t.Decoded)
48 } else {
49 args = append(args, t.Decoded)
50 }
51 }
52
53 if len(args) == 0 {
54 err = errCommandNotSimple("nothing to run", cmd)
55 args = nil
56 env = nil
57 return
58 }
59
60 return
61}

Callers 1

Calls 3

TokenizeFunction · 0.85
errCommandNotSimpleFunction · 0.85
isVariableAssignmentFunction · 0.85

Tested by

no test coverage detected