mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
started the long adventure of unit testing bettercap
This commit is contained in:
parent
889ef0cbe0
commit
cd6fcbf4be
2 changed files with 280 additions and 14 deletions
21
core/core.go
21
core/core.go
|
@ -72,18 +72,11 @@ func ExecSilent(executable string, args []string) (string, error) {
|
|||
}
|
||||
|
||||
func Exec(executable string, args []string) (string, error) {
|
||||
path, err := exec.LookPath(executable)
|
||||
out, err := ExecSilent(executable, args)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
raw, err := exec.Command(path, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: path=%s args=%s err=%s out='%s'\n", path, args, err, raw)
|
||||
return "", err
|
||||
} else {
|
||||
return Trim(string(raw)), nil
|
||||
fmt.Printf("ERROR for '%s %s': %s\n", executable, args, err)
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
func Exists(path string) bool {
|
||||
|
@ -97,12 +90,12 @@ func ExpandPath(path string) (string, error) {
|
|||
// Check if path is empty
|
||||
if path != "" {
|
||||
if strings.HasPrefix(path, "~") {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
if usr, err := user.Current(); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
// Replace only the first occurrence of ~
|
||||
path = strings.Replace(path, "~", usr.HomeDir, 1)
|
||||
}
|
||||
// Replace only the first occurrence of ~
|
||||
path = strings.Replace(path, "~", usr.HomeDir, 1)
|
||||
}
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue