refactor builder in kubectl factory
This commit is contained in:
@@ -238,13 +238,13 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
||||
Flatten()
|
||||
|
||||
if !o.Local {
|
||||
if o.Local {
|
||||
b = b.Local(f.ClientForMapping)
|
||||
} else {
|
||||
b = b.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, o.From).
|
||||
Latest()
|
||||
} else {
|
||||
b = b.Local(f.ClientForMapping)
|
||||
}
|
||||
|
||||
infos, err := b.Do().Infos()
|
||||
@@ -302,13 +302,13 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
||||
Flatten()
|
||||
|
||||
if !o.Local {
|
||||
if o.Local {
|
||||
b = b.Local(f.ClientForMapping)
|
||||
} else {
|
||||
b = b.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
||||
Latest()
|
||||
} else {
|
||||
b = b.Local(f.ClientForMapping)
|
||||
}
|
||||
|
||||
o.Infos, err = b.Do().Infos()
|
||||
|
||||
@@ -147,12 +147,7 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
||||
IncludeUninitialized(includeUninitialized).
|
||||
Flatten()
|
||||
|
||||
if !o.Local {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
||||
Latest()
|
||||
} else {
|
||||
if o.Local {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
@@ -161,6 +156,11 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
||||
}
|
||||
|
||||
builder = builder.Local(f.ClientForMapping)
|
||||
} else {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
||||
Latest()
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
|
||||
@@ -151,12 +151,7 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
||||
IncludeUninitialized(includeUninitialized).
|
||||
Flatten()
|
||||
|
||||
if !o.Local {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
} else {
|
||||
if o.Local {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
@@ -165,6 +160,11 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
||||
}
|
||||
|
||||
builder = builder.Local(f.ClientForMapping)
|
||||
} else {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
|
||||
@@ -132,11 +132,7 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
||||
IncludeUninitialized(includeUninitialized).
|
||||
Flatten()
|
||||
|
||||
if !o.local {
|
||||
o.builder = o.builder.
|
||||
ResourceTypeOrNameArgs(o.all, o.resources...).
|
||||
Latest()
|
||||
} else {
|
||||
if o.local {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
@@ -145,6 +141,10 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
||||
}
|
||||
|
||||
o.builder = o.builder.Local(f.ClientForMapping)
|
||||
} else {
|
||||
o.builder = o.builder.
|
||||
ResourceTypeOrNameArgs(o.all, o.resources...).
|
||||
Latest()
|
||||
}
|
||||
|
||||
o.PrintObject = func(obj runtime.Object) error {
|
||||
|
||||
@@ -133,12 +133,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
IncludeUninitialized(includeUninitialized).
|
||||
Flatten()
|
||||
|
||||
if !o.Local {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
} else {
|
||||
if o.Local {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
@@ -147,6 +142,11 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
}
|
||||
|
||||
builder = builder.Local(f.ClientForMapping)
|
||||
} else {
|
||||
builder = builder.
|
||||
LabelSelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
|
||||
Reference in New Issue
Block a user