mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
add err message if <rsrc>/<name> pairs specified under --local
This commit is contained in:
parent
6003f87b78
commit
c10f4f78bc
@ -150,7 +150,15 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
|||||||
SelectorParam(o.Selector).
|
SelectorParam(o.Selector).
|
||||||
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
||||||
Latest()
|
Latest()
|
||||||
|
} else {
|
||||||
|
// 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.
|
||||||
|
if len(o.Resources) > 0 {
|
||||||
|
return resource.LocalResourceError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Infos, err = builder.Do().Infos()
|
o.Infos, err = builder.Do().Infos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -155,6 +155,13 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
|||||||
SelectorParam(o.Selector).
|
SelectorParam(o.Selector).
|
||||||
ResourceTypeOrNameArgs(o.All, args...).
|
ResourceTypeOrNameArgs(o.All, args...).
|
||||||
Latest()
|
Latest()
|
||||||
|
} else {
|
||||||
|
// 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.
|
||||||
|
if len(args) > 0 {
|
||||||
|
return resource.LocalResourceError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Infos, err = builder.Do().Infos()
|
o.Infos, err = builder.Do().Infos()
|
||||||
|
@ -60,7 +60,7 @@ func TestResourcesLocal(t *testing.T) {
|
|||||||
Requests: "cpu=200m,memory=512Mi",
|
Requests: "cpu=200m,memory=512Mi",
|
||||||
ContainerSelector: "*"}
|
ContainerSelector: "*"}
|
||||||
|
|
||||||
err := opts.Complete(f, cmd, []string{""})
|
err := opts.Complete(f, cmd, []string{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = opts.Validate()
|
err = opts.Validate()
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,13 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
|||||||
o.builder = o.builder.
|
o.builder = o.builder.
|
||||||
ResourceTypeOrNameArgs(o.all, o.resources...).
|
ResourceTypeOrNameArgs(o.all, o.resources...).
|
||||||
Latest()
|
Latest()
|
||||||
|
} else {
|
||||||
|
// 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.
|
||||||
|
if len(o.resources) > 0 {
|
||||||
|
return resource.LocalResourceError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.PrintObject = func(obj runtime.Object) error {
|
o.PrintObject = func(obj runtime.Object) error {
|
||||||
|
@ -137,7 +137,15 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
|||||||
SelectorParam(o.Selector).
|
SelectorParam(o.Selector).
|
||||||
ResourceTypeOrNameArgs(o.All, args...).
|
ResourceTypeOrNameArgs(o.All, args...).
|
||||||
Latest()
|
Latest()
|
||||||
|
} else {
|
||||||
|
// 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.
|
||||||
|
if len(args) > 0 {
|
||||||
|
return resource.LocalResourceError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Infos, err = builder.Do().Infos()
|
o.Infos, err = builder.Do().Infos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -88,6 +89,11 @@ Example resource specifications include:
|
|||||||
'<resource> <name>'
|
'<resource> <name>'
|
||||||
'<resource>'`)
|
'<resource>'`)
|
||||||
|
|
||||||
|
var LocalResourceError = errors.New(`error: you must specify resources by --filename when --local is set.
|
||||||
|
Example resource specifications include:
|
||||||
|
'-f rsrc.yaml'
|
||||||
|
'--filename=rsrc.json'`)
|
||||||
|
|
||||||
// TODO: expand this to include other errors.
|
// TODO: expand this to include other errors.
|
||||||
func IsUsageError(err error) bool {
|
func IsUsageError(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user