From 096ba83f41cd480f65d450838b3e999f152ad231 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 3 Sep 2017 19:34:44 -0400 Subject: [PATCH] refactor: alphabetize more functions --- plugins/common/common.go | 66 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/plugins/common/common.go b/plugins/common/common.go index d9cba64ef..94021f2fe 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -67,32 +67,6 @@ func (sc *ShellCmd) Output() ([]byte, error) { return sc.Command.Output() } -// VerifyAppName verifies app name format and app existence" -func VerifyAppName(appName string) (err error) { - if appName == "" { - return fmt.Errorf("App name must not be null") - } - dokkuRoot := MustGetEnv("DOKKU_ROOT") - appRoot := strings.Join([]string{dokkuRoot, appName}, "/") - if !DirectoryExists(appRoot) { - return fmt.Errorf("App %s does not exist: %v\n", appName, err) - } - r, _ := regexp.Compile("^[a-z].*") - if !r.MatchString(appName) { - return fmt.Errorf("App name (%s) must begin with lowercase alphanumeric character\n", appName) - } - return err -} - -// MustGetEnv returns env variable or fails if it's not set -func MustGetEnv(key string) string { - value := os.Getenv(key) - if value == "" { - LogFail(fmt.Sprintf("%s not set!", key)) - } - return value -} - // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName string) { if appName == "" { @@ -142,13 +116,6 @@ func GetAppImageRepo(appName string) string { return strings.Join([]string{"dokku", appName}, "/") } -// VerifyImage returns true if docker image exists in local repo -func VerifyImage(image string) bool { - imageCmd := NewShellCmd(strings.Join([]string{"docker inspect", image}, " ")) - imageCmd.ShowOutput = false - return imageCmd.Execute() -} - // ContainerIsRunning checks to see if a container is running func ContainerIsRunning(containerID string) bool { b, err := DockerInspect(containerID, "'{{.State.Running}}'") @@ -304,6 +271,15 @@ func IsImageHerokuishBased(image string) bool { return dockerCmd.Execute() } +// MustGetEnv returns env variable or fails if it's not set +func MustGetEnv(key string) string { + value := os.Getenv(key) + if value == "" { + LogFail(fmt.Sprintf("%s not set!", key)) + } + return value +} + // ReadFirstLine gets the first line of a file that has contents and returns it // if there are no contents, an empty string is returned // will also return an empty string if the file does not exist @@ -340,3 +316,27 @@ func StripInlineComments(text string) string { func ToBool(s string) bool { return s == "true" } + +// VerifyAppName verifies app name format and app existence" +func VerifyAppName(appName string) (err error) { + if appName == "" { + return fmt.Errorf("App name must not be null") + } + dokkuRoot := MustGetEnv("DOKKU_ROOT") + appRoot := strings.Join([]string{dokkuRoot, appName}, "/") + if !DirectoryExists(appRoot) { + return fmt.Errorf("App %s does not exist: %v\n", appName, err) + } + r, _ := regexp.Compile("^[a-z].*") + if !r.MatchString(appName) { + return fmt.Errorf("App name (%s) must begin with lowercase alphanumeric character\n", appName) + } + return err +} + +// VerifyImage returns true if docker image exists in local repo +func VerifyImage(image string) bool { + imageCmd := NewShellCmd(strings.Join([]string{"docker inspect", image}, " ")) + imageCmd.ShowOutput = false + return imageCmd.Execute() +}