-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
40 lines (32 loc) · 777 Bytes
/
main.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
package variant
import (
"fmt"
"io"
"github.com/mumoshu/variant2/pkg/controller"
)
func RunMain(env Env, opts ...Option) error {
cmd, path, args := GetPathAndArgsFromEnv(env)
m, err := Load(FromPath(path, func(m *Main) {
m.Command = cmd
for _, o := range opts {
o(m)
}
}))
if err != nil {
return fmt.Errorf("loading command: %w", err)
}
if controller.RunRequested() {
return controller.Run(func(args []string) (string, error) {
out, err := controller.CaptureOutput(func(stdout, stderr io.Writer) error {
return m.Run(args, RunOptions{
Stdout: stdout,
Stderr: stdout,
DisableLocking: false,
})
})
//nolint:wrapcheck
return out, err
})
}
return m.Run(args, RunOptions{DisableLocking: false})
}