add resource prefix to multiple items w/ same kind

This patch ensures that a resource prefix is added to multiple items of
the same kind, when using `oc get all`. Before, a prefix was added only
when a single item was returned on `oc get all`, but ignored if only a
single resource kind existed but multiple items for that kind were
returned.
This commit is contained in:
juanvallejo
2016-11-29 12:25:10 -05:00
parent 7d611fe32b
commit 3484c6f676
4 changed files with 89 additions and 15 deletions

View File

@@ -803,3 +803,36 @@ func HasNames(args []string) (bool, error) {
}
return hasCombinedTypes || len(args) > 1, nil
}
// MultipleTypesRequested returns true if the provided args contain multiple resource kinds
func MultipleTypesRequested(args []string) bool {
args = normalizeMultipleResourcesArgs(args)
rKinds := sets.NewString()
for _, arg := range args {
if arg == "all" {
return true
}
rTuple, found, err := splitResourceTypeName(arg)
if err != nil {
continue
}
// if tuple not found, assume arg is of the form "type1,type2,...".
// Since SplitResourceArgument returns a unique list of kinds,
// return true here if len(uniqueList) > 1
if !found {
if strings.Contains(arg, ",") {
splitArgs := SplitResourceArgument(arg)
if len(splitArgs) > 1 {
return true
}
}
continue
}
if rKinds.Has(rTuple.Resource) {
continue
}
rKinds.Insert(rTuple.Resource)
}
return (rKinds.Len() > 1)
}