MCPcopy
hub / github.com/lmorg/murex / parseRedirection

Function parseRedirection

lang/redirection.go:11–79  ·  view source on GitHub ↗
(p *Process)

Source from the content-addressed store, hash-verified

9)
10
11func parseRedirection(p *Process) {
12 //p.NamedPipeOut = "out"
13 //p.NamedPipeErr = "err"
14
15 for _, name := range p.namedPipes {
16 switch {
17 case len(name) > 5 && name[:5] == "test_":
18 if p.NamedPipeTest == "" {
19 testEnabled, err := p.Config.Get("test", "enabled", types.Boolean)
20 if err == nil && testEnabled.(bool) {
21 p.NamedPipeTest = name[5:]
22 }
23 } else {
24 pipeErr(p, "you specified test multiple times")
25 }
26
27 case len(name) > 6 && name[:6] == "state_":
28 if p.NamedPipeTest == "" {
29 testEnabled, err := p.Config.Get("test", "enabled", types.Boolean)
30 if err == nil && testEnabled.(bool) {
31 p.testState = append(p.testState, name[6:])
32 }
33 }
34
35 case len(name) > 4 && name[:4] == "env:":
36 p.Envs = append(p.Envs, name[4:])
37
38 case len(name) > 4 && name[:4] == "fid:":
39 varName := name[4:]
40 err := p.Variables.Set(p, varName, int(p.Id), types.Integer)
41 if err != nil {
42 ShellProcess.Stderr.Writeln([]byte(
43 fmt.Sprintf("Cannot write variable '%s': %s", varName, err.Error()),
44 ))
45 }
46
47 case len(name) > 4 && name[:4] == "pid:":
48 varName := name[4:]
49 go func() {
50 err := p.Variables.Set(p, varName, p.SystemProcess.WaitForPid(), types.Integer)
51 if err != nil {
52 ShellProcess.Stderr.Writeln([]byte(
53 fmt.Sprintf("Cannot write variable '%s': %s", varName, err.Error()),
54 ))
55 }
56 }()
57
58 case name[0] == '!':
59 if p.NamedPipeErr == "" {
60 p.NamedPipeErr = name[1:]
61 } else {
62 pipeErr(p, "you specified stderr multiple times")
63 }
64
65 case strings.Contains(name, ":"):
66 err := parseRedirectionTemp(p, name)
67 if err != nil {
68 pipeErr(p, err.Error())

Callers 1

createProcessFunction · 0.85

Calls 7

pipeErrFunction · 0.85
parseRedirectionTempFunction · 0.85
WaitForPidMethod · 0.80
SetMethod · 0.65
WritelnMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected