Tweak explain messages and abstract client

This commit is contained in:
Clayton Coleman
2015-12-11 17:15:41 -05:00
parent 08c2cba266
commit 151b4e5958
5 changed files with 31 additions and 21 deletions

View File

@@ -24,27 +24,16 @@ import (
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
apiutil "k8s.io/kubernetes/pkg/api/util"
client "k8s.io/kubernetes/pkg/client/unversioned"
)
var allModels = make(map[string]*swagger.NamedModel)
var recursive = false // this is global for convenience, can become int for multiple levels
// GetSwaggerSchema returns the swagger spec from master
func GetSwaggerSchema(version unversioned.GroupVersion, kubeClient client.Interface) (*swagger.ApiDeclaration, error) {
swaggerSchema, err := kubeClient.SwaggerSchema(version)
if err != nil {
return nil, fmt.Errorf("couldn't read swagger schema from server: %v", err)
}
return swaggerSchema, nil
}
// SplitAndParseResourceRequest separates the users input into a model and fields
func SplitAndParseResourceRequest(inResource string, mapper meta.RESTMapper) (string, []string, error) {
inResource, fieldsPath := splitDotNotation(inResource)
inResource, _ = mapper.ResourceSingularizer(expandResourceShortcut(inResource))
inResource, _ = mapper.ResourceSingularizer(inResource)
return inResource, fieldsPath, nil
}
@@ -63,7 +52,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
}
}
if pointedModel == nil {
return fmt.Errorf("Requested resource: %s doesn't exist", inModel)
return fmt.Errorf("requested resource %q is not defined", inModel)
}
if len(fieldsPath) == 0 {
@@ -80,7 +69,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
return printPrimitive(w, prop)
}
} else {
return fmt.Errorf("field: %s doesn't exist", field)
return fmt.Errorf("field %q does not exist", field)
}
}
return printModelInfo(w, pointedModel, pointedModelAsProp)