hack: parse out the info flags for report subcommands separately

pflag doesn't ignore unspecified arguments, so they must be parsed out separately first.
This commit is contained in:
Jose Diaz-Gonzalez
2020-12-21 01:36:59 -05:00
parent 8240790381
commit 1439e8b30b
13 changed files with 56 additions and 58 deletions

View File

@@ -286,6 +286,26 @@ func GetenvWithDefault(key string, defaultValue string) (val string) {
return
}
func ParseReportArgs(pluginName string, arguments []string) ([]string, string, error) {
osArgs := []string{}
infoFlags := []string{}
for _, argument := range arguments {
if strings.HasPrefix(argument, "--") {
infoFlags = append(infoFlags, argument)
} else {
osArgs = append(osArgs, argument)
}
}
if len(infoFlags) == 0 {
return osArgs, "", nil
}
if len(infoFlags) == 1 {
return osArgs, infoFlags[0], nil
}
return osArgs, "", fmt.Errorf("%s:report command allows only a single flag", pluginName)
}
// ReportSingleApp is an internal function that displays a report for an app
func ReportSingleApp(reportType string, appName string, infoFlag string, infoFlags map[string]string, trimPrefix bool, uppercaseFirstCharacter bool) error {
flags := []string{}