-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.go
More file actions
61 lines (48 loc) · 1.05 KB
/
Copy pathshell.go
File metadata and controls
61 lines (48 loc) · 1.05 KB
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
package ku
import (
"os"
"strings"
"github.com/mgenware/j9/v3"
"github.com/mgenware/ku-builder/util"
)
type Shell struct {
Args *CLIArgs
Tunnel *j9.Tunnel
shellCache *util.StringCache
}
func NewShell(tunnel *j9.Tunnel, args *CLIArgs) *Shell {
return &Shell{
Tunnel: tunnel,
Args: args,
shellCache: util.NewStringCache(),
}
}
func (s *Shell) Shell(cmd string) string {
output := s.Tunnel.Shell(&j9.ShellOpt{
Cmd: cmd})
return strings.TrimSpace(string(output))
}
func (s *Shell) ShellCached(cmd string) string {
return s.shellCache.Get(cmd, func() string {
return s.Shell(cmd)
})
}
func (s *Shell) Spawn(opt *j9.SpawnOpt) {
s.Tunnel.Spawn(opt)
}
func (s *Shell) SpawnRaw(opt *j9.SpawnOpt) error {
return s.Tunnel.SpawnRaw(opt)
}
func (s *Shell) Logger() j9.Logger {
return s.Tunnel.Logger()
}
func (s *Shell) Log(level int, message string) {
s.Tunnel.Logger().Log(level, message)
}
func (s *Shell) CD(dir string) {
s.Tunnel.CD(dir)
}
func (s *Shell) Quit(msg string) {
s.Tunnel.Logger().Log(j9.LogLevelError, msg)
os.Exit(1)
}