Fixes get --show-all

This commit is contained in:
Fabiano Franz
2015-12-03 17:32:22 -02:00
parent a45c87864e
commit 717896eae3
5 changed files with 126 additions and 21 deletions

View File

@@ -282,23 +282,7 @@ func (b *Builder) SelectAllParam(selectAll bool) *Builder {
// When two or more arguments are received, they must be a single type and resource name(s).
// The allowEmptySelector permits to select all the resources (via Everything func).
func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string) *Builder {
// convert multiple resources to resource tuples, a,b,c d as a transform to a/d b/d c/d
if len(args) >= 2 {
resources := []string{}
resources = append(resources, SplitResourceArgument(args[0])...)
if len(resources) > 1 {
names := []string{}
names = append(names, args[1:]...)
newArgs := []string{}
for _, resource := range resources {
for _, name := range names {
newArgs = append(newArgs, strings.Join([]string{resource, name}, "/"))
}
}
args = newArgs
}
}
args = normalizeMultipleResourcesArgs(args)
if ok, err := hasCombinedTypeArgs(args); ok {
if err != nil {
b.errs = append(b.errs, err)
@@ -369,6 +353,27 @@ func hasCombinedTypeArgs(args []string) (bool, error) {
}
}
// Normalize args convert multiple resources to resource tuples, a,b,c d
// as a transform to a/d b/d c/d
func normalizeMultipleResourcesArgs(args []string) []string {
if len(args) >= 2 {
resources := []string{}
resources = append(resources, SplitResourceArgument(args[0])...)
if len(resources) > 1 {
names := []string{}
names = append(names, args[1:]...)
newArgs := []string{}
for _, resource := range resources {
for _, name := range names {
newArgs = append(newArgs, strings.Join([]string{resource, name}, "/"))
}
}
return newArgs
}
}
return args
}
// splitResourceTypeName handles type/name resource formats and returns a resource tuple
// (empty or not), whether it successfully found one, and an error
func splitResourceTypeName(s string) (resourceTuple, bool, error) {
@@ -697,3 +702,13 @@ func SplitResourceArgument(arg string) []string {
}
return out
}
// HasNames returns true if the provided args contain resource names
func HasNames(args []string) (bool, error) {
args = normalizeMultipleResourcesArgs(args)
hasCombinedTypes, err := hasCombinedTypeArgs(args)
if err != nil {
return false, err
}
return hasCombinedTypes || len(args) > 1, nil
}