[config] clean up PlugnTrigger and NewShellCmd

This commit is contained in:
Alex Quick committed 2017-10-12 22:38:18 -04:00
1 parent c896ca700c
commit ad8bcecb5b
1 file changed
+8 -12
+8 -12
View File
@@ -25,16 +25,11 @@ type ShellCmd struct {
// NewShellCmd returns a new ShellCmd struct // NewShellCmd returns a new ShellCmd struct
func NewShellCmd(command string) *ShellCmd { func NewShellCmd(command string) *ShellCmd {
items := strings.Split(command, " ") items := strings.Split(command, " ")
return NewTokenizedShellCmd(items...) cmd := items[0]
} args := items[1:]
// NewTokenizedShellCmd creates a new ShellCmd
func NewTokenizedShellCmd(command ...string) *ShellCmd {
cmd := command[0]
args := command[1:]
return &ShellCmd{ return &ShellCmd{
Command: exec.Command(cmd, args...), Command: exec.Command(cmd, args...),
CommandString: strings.Join(command, " "), CommandString: command,
Args: args, Args: args,
ShowOutput: true, ShowOutput: true,
} }
@@ -351,10 +346,11 @@ func VerifyImage(image string) bool {
//PlugnTrigger fire the given plugn trigger with the given args //PlugnTrigger fire the given plugn trigger with the given args
func PlugnTrigger(triggerName string, args ...string) (string, error) { func PlugnTrigger(triggerName string, args ...string) (string, error) {
shellArgs := make([]interface{}, 0, len(args)) shellArgs := make([]interface{}, len(args)+2)
shellArgs = append(shellArgs, "trigger", triggerName) shellArgs[0] = "trigger"
for _, arg := range args { shellArgs[1] = triggerName
shellArgs = append(shellArgs, arg) for i, arg := range args {
shellArgs[i+2] = arg
} }
res, err := sh.Command("plugn", shellArgs...).Output() res, err := sh.Command("plugn", shellArgs...).Output()
return string(res), err return string(res), err