/
procs.go
89 lines (76 loc) · 2.8 KB
/
procs.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gexe
import (
"fmt"
"github.com/vladimirvivien/gexe/exec"
)
// NewProc setups a new process with specified command cmdStr and returns immediately
// without starting. Use Proc.Wait to wait for exection and then retrieve process result.
// Information about the running process is stored in *exec.Proc.
func (e *Echo) NewProc(cmdStr string) *exec.Proc {
return exec.NewProc(cmdStr)
}
// StartProc executes the command in cmdStr and returns immediately
// without waiting. Use Proc.Wait to wait for exection and then retrieve process result.
// Information about the running process is stored in *Proc.
func (e *Echo) StartProc(cmdStr string) *exec.Proc {
return exec.StartProc(e.Eval(cmdStr))
}
// RunProc executes command in cmdStr and waits for the result.
// It returns a *Proc with information about the executed process.
func (e *Echo) RunProc(cmdStr string) *exec.Proc {
return exec.RunProc(e.Eval(cmdStr))
}
// Run executes cmdStr, waits, and returns the result as a string.
func (e *Echo) Run(cmdStr string) string {
return exec.Run(e.Eval(cmdStr))
}
// Runout executes command cmdStr and prints out the result
func (e *Echo) Runout(cmdStr string) {
fmt.Print(e.Run(cmdStr))
}
// Commands returns a *exe.CommandBuilder to build a multi-command execution flow.
func (e *Echo) Commands(cmdStrs ...string) *exec.CommandBuilder {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...)
}
// StartAll starts the sequential execution of each command, in cmdStrs, and does not
// wait for their completion.
func (e *Echo) StartAll(cmdStrs ...string) *exec.CommandResult {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...).Start()
}
// RunAll executes each command sequentially, in cmdStrs, and wait for their completion.
func (e *Echo) RunAll(cmdStrs ...string) *exec.CommandResult {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...).Run()
}
// StartConcur starts the concurrent execution of each command, in cmdStrs, and does not
// wait for their completion.
func (e *Echo) StartConcur(cmdStrs ...string) *exec.CommandResult {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...).Concurr()
}
// RunConcur executes each command concurrently, in cmdStrs, and waits
// their completion.
func (e *Echo) RunConcur(cmdStrs ...string) *exec.CommandResult {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...).Concurr().Wait()
}
// Pipe executes each command, in cmdStrs, by piping the result
// of the previous command as input to the next command until done.
func (e *Echo) Pipe(cmdStrs ...string) *exec.PipedCommandResult {
for i, cmd := range cmdStrs {
cmdStrs[i] = e.Eval(cmd)
}
return exec.Commands(cmdStrs...).Pipe()
}