-
Notifications
You must be signed in to change notification settings - Fork 1
/
exe.go
122 lines (103 loc) · 3.12 KB
/
exe.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Package exe enables template completion before command execution.
package exe // import "aduu.dev/utils/exe"
import (
"context"
"os/exec"
)
// Run runs the function on the default Runner.
func Run(cmd *exec.Cmd, name string, settings ...SettingsFunc) {
r := DefaultRunner()
r.Run(cmd, name, settings...)
}
// RunE runs the function on the default Runner.
func RunE(cmd *exec.Cmd, name string, settings ...SettingsFunc) (err error) {
r := DefaultRunner()
return r.RunE(cmd, name, settings...)
}
// RunWithOutput runs the function on the default Runner.
func RunWithOutput(cmd *exec.Cmd, name string, settings ...SettingsFunc) string {
r := DefaultRunner()
return r.RunWithOutput(cmd, name, settings...)
}
// RunWithOutputE runs the function on the default Runner.
func RunWithOutputE(cmd *exec.Cmd, name string, settings ...SettingsFunc) (out string, err error) {
r := DefaultRunner()
return r.RunWithOutputE(cmd, name, settings...)
}
func search(text []rune, what string) int {
whatRunes := []rune(what)
for i := range text {
found := true
for j := range whatRunes {
if text[i+j] != whatRunes[j] {
found = false
break
}
}
if found {
return i
}
}
return -1
}
// SplitCommand runs the function on the default Runner.
func SplitCommand(s string) []string {
r := DefaultRunner()
return r.SplitCommand(s)
}
/*
func splitCommand2(s string) []string {
input := s
var values []string
for len(s) != 0 {
if s[0] == '"' {
next := strings.Index(s[1:], "\"")
if next == -1 {
panic("no matching \": " + input)
}
values = append(values, s[1:next+1])
s = s[next+2:]
} else {
next := strings.Index(s, " ")
if next == -1 {
values = append(values, s)
s = ""
break
}
values = append(values, s[:next])
s = s[next+1:]
}
}
return values
}
*/
// Execute runs the function on the default Runner.
func Execute(s string, obj interface{}, settings ...SettingsFunc) *exec.Cmd {
r := DefaultRunner()
return r.Execute(s, obj, settings...)
}
// ExecuteE runs the function on the default Runner.
func ExecuteE(s string, obj interface{}, settings ...SettingsFunc) (*exec.Cmd, error) {
r := DefaultRunner()
return r.ExecuteE(s, obj, settings...)
}
// Execute runs the function on the default Runner.
func ExecuteWithContext(ctx context.Context, s string, obj interface{}, settings ...SettingsFunc) *exec.Cmd {
r := DefaultRunner()
return r.ExecuteWithContext(ctx, s, obj, settings...)
}
// ExecuteE runs the function on the default Runner.
func ExecuteEWithContext(ctx context.Context, s string, obj interface{}, settings ...SettingsFunc) (*exec.Cmd, error) {
r := DefaultRunner()
return r.ExecuteEWithContext(ctx, s, obj, settings...)
}
// ExecuteWithOutput runs the function on the default Runner.
func ExecuteWithOutput(s string, obj interface{}, settings ...SettingsFunc) string {
r := DefaultRunner()
return r.ExecuteWithOutput(s, obj, settings...)
}
// ExecuteWithOutputE runs the command on the default runner.
func ExecuteWithOutputE(s string, obj interface{}, settings ...SettingsFunc) (out string, err error) {
r := DefaultRunner()
return r.ExecuteWithOutputE(s, obj, settings...)
}