add err message if <rsrc>/<name> pairs specified under --local

This commit is contained in:
juanvallejo 2017-07-11 10:19:27 -04:00
parent 6003f87b78
commit c10f4f78bc
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D
6 changed files with 37 additions and 1 deletions

View File

@ -150,7 +150,15 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, o.Resources...).
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()
if err != nil {
return err

View File

@ -155,6 +155,13 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, args...).
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()

View File

@ -60,7 +60,7 @@ func TestResourcesLocal(t *testing.T) {
Requests: "cpu=200m,memory=512Mi",
ContainerSelector: "*"}
err := opts.Complete(f, cmd, []string{""})
err := opts.Complete(f, cmd, []string{})
if err == nil {
err = opts.Validate()
}

View File

@ -134,6 +134,13 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
o.builder = o.builder.
ResourceTypeOrNameArgs(o.all, o.resources...).
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 {

View File

@ -137,7 +137,15 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, args...).
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()
if err != nil {
return err

View File

@ -17,6 +17,7 @@ limitations under the License.
package resource
import (
"errors"
"fmt"
"io"
"net/url"
@ -88,6 +89,11 @@ Example resource specifications include:
'<resource> <name>'
'<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.
func IsUsageError(err error) bool {
if err == nil {