-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
plugn.go
68 lines (55 loc) · 1.91 KB
/
plugn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package common
import (
"context"
"fmt"
"io"
"os"
"strings"
)
// PlugnTriggerInput is the input for CallPlugnTrigger
type PlugnTriggerInput struct {
// Args are the arguments to pass to the trigger
Args []string
// DisableStdioBuffer disables the stdio buffer
DisableStdioBuffer bool
// Env is the environment variables to pass to the trigger
Env map[string]string
// Stdin is the stdin of the command
Stdin io.Reader
// StreamStdio determines whether to stream the stdio of the trigger
StreamStdio bool
// StreamStdout prints stdout directly to os.Stdout as the command runs.
StreamStdout bool
// StreamStderr prints stderr directly to os.Stderr as the command runs.
StreamStderr bool
// Trigger is the trigger to execute
Trigger string
}
// CallPlugnTrigger executes a trigger via plugn
func CallPlugnTrigger(input PlugnTriggerInput) (ExecCommandResponse, error) {
return CallPlugnTriggerWithContext(context.Background(), input)
}
// CallPlugnTriggerWithContext executes a trigger via plugn with the given context
func CallPlugnTriggerWithContext(ctx context.Context, input PlugnTriggerInput) (ExecCommandResponse, error) {
args := []string{"trigger", input.Trigger}
args = append(args, input.Args...)
result, err := CallExecCommandWithContext(ctx, ExecCommandInput{
Command: "plugn",
Args: args,
DisableStdioBuffer: input.DisableStdioBuffer,
Env: input.Env,
Stdin: input.Stdin,
StreamStdio: input.StreamStdio,
StreamStdout: input.StreamStdout,
StreamStderr: input.StreamStderr,
})
if os.Getenv("DOKKU_TRACE") == "1" {
for _, line := range strings.Split(result.Stderr, "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stderr: %s", input.Trigger, line))
}
for _, line := range strings.Split(result.Stdout, "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stdout: %s", input.Trigger, line))
}
}
return result, err
}