-
Notifications
You must be signed in to change notification settings - Fork 183
/
cliutil.go
42 lines (35 loc) · 1.17 KB
/
cliutil.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
// Package cliutil provides some util functions for CLI
package cliutil
import (
"github.com/gookit/goutil/sysutil"
)
// QuickExec quick exec an simple command line
func QuickExec(cmdLine string, workDir ...string) (string, error) {
return sysutil.QuickExec(cmdLine, workDir...)
}
// ExecCmd a CLI bin file and return output.
// Usage:
// ExecCmd("ls", []string{"-al"})
func ExecCmd(binName string, args []string, workDir ...string) (string, error) {
return sysutil.ExecCmd(binName, args, workDir...)
}
// ExecCommand alias of the ExecCmd()
func ExecCommand(binName string, args []string, workDir ...string) (string, error) {
return sysutil.ExecCmd(binName, args, workDir...)
}
// ShellExec exec command by shell
// cmdStr eg. "ls -al"
func ShellExec(cmdLine string, shells ...string) (string, error) {
return sysutil.ShellExec(cmdLine, shells...)
}
// CurrentShell get current used shell env file. eg "/bin/zsh" "/bin/bash"
func CurrentShell(onlyName bool) (path string) {
return sysutil.CurrentShell(onlyName)
}
// HasShellEnv has shell env check.
// Usage:
// HasShellEnv("sh")
// HasShellEnv("bash")
func HasShellEnv(shell string) bool {
return sysutil.HasShellEnv(shell)
}