Unify Object and UnstructuredObject

The unified RESTMapper and Typer follow the new rules, but on error will
fallback to the legacy path (while still supporting Unstructured
objects). This allows callers to handle the appropriate distinction
themselves if necessary.

Add a LocalParam() method to the resource.Builder that DRYs up a large
chunk of complicated code in set commands.
This commit is contained in:
Clayton Coleman
2017-11-14 23:03:06 -05:00
parent 7563a0c4d8
commit 04ab96d2bd
18 changed files with 135 additions and 156 deletions

View File

@@ -191,13 +191,9 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
changeCause := f.Command(cmd, false)
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
b := f.NewBuilder()
if o.local {
b = b.Local()
} else {
b = b.Unstructured()
}
b = b.
b := f.NewBuilder().
Unstructured().
LocalParam(o.local).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, &o.FilenameOptions).
@@ -304,16 +300,10 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
return nil
}
var mapper meta.RESTMapper
if o.local {
mapper, _ = f.Object()
} else {
mapper, _ = f.UnstructuredObject()
}
if o.outputFormat != "" {
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
return f.PrintObject(cmd, o.local, r.Mapper().RESTMapper, outputObj, o.out)
}
f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
f.PrintSuccess(r.Mapper().RESTMapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
return nil
})
}