refactor: clean up duplication in retrieving and verifying the APP argument

This commit is contained in:
Jose Diaz-Gonzalez committed 2019-04-08 11:31:34 -04:00
1 parent c5717510ee
commit ab9f516c08
1 file changed
+18 -24
+18 -24
View File
@@ -8,16 +8,9 @@ import (
// CommandLimit implements resource:limit // CommandLimit implements resource:limit
func CommandLimit(args []string, processType string, r Resource, global bool) (err error) { func CommandLimit(args []string, processType string, r Resource, global bool) (err error) {
appName := "_all_" appName, err = getAppName(args, global)
if !global {
appName, err = getAppName(args)
if err != nil { if err != nil {
return return err
}
if err = common.VerifyAppName(appName); err != nil {
common.LogFail(err.Error())
}
} }
return setRequestType(appName, processType, r, "limit") return setRequestType(appName, processType, r, "limit")
@@ -30,16 +23,9 @@ func CommandLimitClear(args []string, processType string, global bool) (err erro
// CommandReserve implements resource:reserve // CommandReserve implements resource:reserve
func CommandReserve(args []string, processType string, r Resource, global bool) (err error) { func CommandReserve(args []string, processType string, r Resource, global bool) (err error) {
appName := "_all_" appName, err = getAppName(args, global)
if !global {
appName, err = getAppName(args)
if err != nil { if err != nil {
return return err
}
if err = common.VerifyAppName(appName); err != nil {
common.LogFail(err.Error())
}
} }
return setRequestType(appName, processType, r, "reserve") return setRequestType(appName, processType, r, "reserve")
@@ -141,12 +127,20 @@ func propertyKey(processType string, requestType string, key string) string {
return fmt.Sprintf("%v.%v.%v", processType, requestType, key) return fmt.Sprintf("%v.%v.%v", processType, requestType, key)
} }
func getAppName(args []string) (appName string, err error) { func getAppName(args []string, global bool) (appName string, err error) {
if len(args) >= 1 { appName := "_all_"
appName = args[0] if global {
} else { return appName, nil
err = errors.New("Please specify an app to run the command on")
} }
return if len(args) < 1 {
return "", errors.New("Please specify an app to run the command on")
}
appName = args[0]
if err = common.VerifyAppName(appName); err != nil {
return "", err
}
return appName, nil
} }