Support setting up aliases for groups of resources

Closes #5278
This commit is contained in:
kargakis
2015-04-08 17:05:41 +02:00
parent 8510fc67ff
commit 9d056c6bd8
7 changed files with 86 additions and 0 deletions

View File

@@ -230,6 +230,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 {
args = b.replaceAliases(args)
if ok, err := hasCombinedTypeArgs(args); ok {
if err != nil {
b.errs = append(b.errs, err)
@@ -269,6 +270,18 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
return b
}
func (b *Builder) replaceAliases(args []string) []string {
replaced := []string{}
for _, arg := range args {
if aliases, ok := b.mapper.AliasesForResource(arg); ok {
arg = strings.Join(aliases, ",")
}
replaced = append(replaced, arg)
}
return replaced
}
func hasCombinedTypeArgs(args []string) (bool, error) {
hasSlash := 0
for _, s := range args {