move category expansion out of restmapper

This commit is contained in:
deads2k
2017-03-24 08:02:10 -04:00
parent f4986235c7
commit 8895f314b4
51 changed files with 298 additions and 245 deletions

View File

@@ -42,7 +42,8 @@ const defaultHttpGetAttempts int = 3
// from the command line and converting them to a list of resources to iterate
// over using the Visitor interface.
type Builder struct {
mapper *Mapper
mapper *Mapper
categoryExpander CategoryExpander
errs []error
@@ -105,10 +106,11 @@ type resourceTuple struct {
}
// NewBuilder creates a builder that operates on generic objects.
func NewBuilder(mapper meta.RESTMapper, typer runtime.ObjectTyper, clientMapper ClientMapper, decoder runtime.Decoder) *Builder {
func NewBuilder(mapper meta.RESTMapper, categoryExpander CategoryExpander, typer runtime.ObjectTyper, clientMapper ClientMapper, decoder runtime.Decoder) *Builder {
return &Builder{
mapper: &Mapper{typer, mapper, clientMapper, decoder},
requireObject: true,
mapper: &Mapper{typer, mapper, clientMapper, decoder},
categoryExpander: categoryExpander,
requireObject: true,
}
}
@@ -371,8 +373,16 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
func (b *Builder) ReplaceAliases(input string) string {
replaced := []string{}
for _, arg := range strings.Split(input, ",") {
if aliases, ok := b.mapper.AliasesForResource(arg); ok {
arg = strings.Join(aliases, ",")
if resources, ok := b.categoryExpander.Expand(arg); ok {
asStrings := []string{}
for _, resource := range resources {
if len(resource.Group) == 0 {
asStrings = append(asStrings, resource.Resource)
continue
}
asStrings = append(asStrings, resource.Resource+"."+resource.Group)
}
arg = strings.Join(asStrings, ",")
}
replaced = append(replaced, arg)
}