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:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user