From 09b656e37e6dc865ac9e58bc58c5e3e4703d0c4b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 22 Feb 2020 04:30:40 -0500 Subject: [PATCH] refactor: standardize plugin trigger calls --- plugins/common/common.go | 19 +++++++++++++++---- plugins/network/network.go | 6 ++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/common/common.go b/plugins/common/common.go index 19cb1195a..dbd8ae76a 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -75,19 +75,19 @@ func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName st LogFail("(GetDeployingAppImageName) APP must not be empty") } - b, err := sh.Command("plugn", "trigger", "deployed-app-repository", appName).Output() + b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) if err != nil { LogFail(err.Error()) } imageRemoteRepository := string(b[:]) - b, err = sh.Command("plugn", "trigger", "deployed-app-image-tag", appName).Output() + b, err = PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) if err != nil { LogFail(err.Error()) } newImageTag := string(b[:]) - b, err = sh.Command("plugn", "trigger", "deployed-app-image-repo", appName).Output() + b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) if err != nil { LogFail(err.Error()) } @@ -456,7 +456,7 @@ func DockerBin() string { return dockerBin } -//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) error { shellArgs := make([]interface{}, len(args)+2) shellArgs[0] = "trigger" @@ -467,6 +467,17 @@ func PlugnTrigger(triggerName string, args ...string) error { return sh.Command("plugn", shellArgs...).Run() } +// PlugnTriggerOutput fire the given plugn trigger with the given args +func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) { + shellArgs := make([]interface{}, len(args)+2) + shellArgs[0] = "trigger" + shellArgs[1] = triggerName + for i, arg := range args { + shellArgs[i+2] = arg + } + return sh.Command("plugn", shellArgs...).Output() +} + func times(str string, n int) (out string) { for i := 0; i < n; i++ { out += str diff --git a/plugins/network/network.go b/plugins/network/network.go index 4516b36ed..6751a967a 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -75,14 +75,16 @@ func BuildConfig(appName string) { port := GetContainerPort(appName, processType, isHerokuishContainer, containerID) if ipAddress != "" { - _, err := sh.Command("plugn", "trigger", "network-write-ipaddr", appName, processType, containerIndexString, ipAddress).Output() + args := []string{appName, processType, containerIndexString, ipAddress} + _, err := common.PlugnTriggerOutput("network-write-ipaddr", args...) if err != nil { common.LogWarn(err.Error()) } } if port != "" { - _, err := sh.Command("plugn", "trigger", "network-write-port", appName, processType, containerIndexString, port).Output() + args := []string{appName, processType, containerIndexString, port} + _, err := common.PlugnTriggerOutput("network-write-port", args...) if err != nil { common.LogWarn(err.Error()) }