refactor: move ParseScaleOutput to common.go so that it can be used by all plugins

This commit is contained in:
Jose Diaz-Gonzalez
2021-08-01 16:29:50 -04:00
parent bd4621070c
commit a1dcc2c173
2 changed files with 18 additions and 17 deletions

View File

@@ -353,6 +353,23 @@ func ParseReportArgs(pluginName string, arguments []string) ([]string, string, e
return osArgs, "", fmt.Errorf("%s:report command allows only a single flag", pluginName)
}
// ParseScaleOutput allows golang plugins to properly parse the output of ps-current-scale
func ParseScaleOutput(b []byte) (map[string]int, error) {
scale := make(map[string]int)
for _, line := range strings.Split(string(b), "\n") {
s := strings.Split(line, "=")
processType := s[0]
count, err := strconv.Atoi(s[1])
if err != nil {
return scale, err
}
scale[processType] = count
}
return scale, nil
}
// ReportSingleApp is an internal function that displays a report for an app
func ReportSingleApp(reportType string, appName string, infoFlag string, infoFlags map[string]string, infoFlagKeys []string, format string, trimPrefix bool, uppercaseFirstCharacter bool) error {
if format != "stdout" && infoFlag != "" {

View File

@@ -34,22 +34,6 @@ var (
}
)
func parseScaleOutput(b []byte) (map[string]int, error) {
scale := make(map[string]int)
for _, line := range strings.Split(string(b), "\n") {
s := strings.Split(line, "=")
processType := s[0]
count, err := strconv.Atoi(s[1])
if err != nil {
return scale, err
}
scale[processType] = count
}
return scale, nil
}
// BuildConfig builds network config files
func BuildConfig(appName string) error {
if !common.IsDeployed(appName) {
@@ -62,7 +46,7 @@ func BuildConfig(appName string) error {
return err
}
scale, err := parseScaleOutput(s)
scale, err := common.ParseScaleOutput(s)
if err != nil {
return err
}