mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
cmd/explain: make 'recursive' local var (not global)
This commit is contained in:
parent
bc5d723c57
commit
b458c2fd26
@ -28,7 +28,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var allModels = make(map[string]*swagger.NamedModel)
|
var allModels = make(map[string]*swagger.NamedModel)
|
||||||
var recursive = false // this is global for convenience, can become int for multiple levels
|
|
||||||
|
|
||||||
// SplitAndParseResourceRequest separates the users input into a model and fields
|
// SplitAndParseResourceRequest separates the users input into a model and fields
|
||||||
func SplitAndParseResourceRequest(inResource string, mapper meta.RESTMapper) (string, []string, error) {
|
func SplitAndParseResourceRequest(inResource string, mapper meta.RESTMapper) (string, []string, error) {
|
||||||
@ -37,9 +36,10 @@ func SplitAndParseResourceRequest(inResource string, mapper meta.RESTMapper) (st
|
|||||||
return inResource, fieldsPath, nil
|
return inResource, fieldsPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintModelDescription prints the description of a specific model or dot path
|
// PrintModelDescription prints the description of a specific model or dot path.
|
||||||
func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swaggerSchema *swagger.ApiDeclaration, r bool) error {
|
// If recursive, all components nested within the fields of the schema will be
|
||||||
recursive = r // this is global for convenience
|
// printed.
|
||||||
|
func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swaggerSchema *swagger.ApiDeclaration, recursive bool) error {
|
||||||
apiVer := apiutil.GetVersion(swaggerSchema.ApiVersion) + "."
|
apiVer := apiutil.GetVersion(swaggerSchema.ApiVersion) + "."
|
||||||
|
|
||||||
var pointedModel *swagger.NamedModel
|
var pointedModel *swagger.NamedModel
|
||||||
@ -56,7 +56,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(fieldsPath) == 0 {
|
if len(fieldsPath) == 0 {
|
||||||
return printTopLevelResourceInfo(w, pointedModel)
|
return printTopLevelResourceInfo(w, pointedModel, recursive)
|
||||||
}
|
}
|
||||||
|
|
||||||
var pointedModelAsProp *swagger.NamedModelProperty
|
var pointedModelAsProp *swagger.NamedModelProperty
|
||||||
@ -72,7 +72,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
|
|||||||
return fmt.Errorf("field %q does not exist", field)
|
return fmt.Errorf("field %q does not exist", field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return printModelInfo(w, pointedModel, pointedModelAsProp)
|
return printModelInfo(w, pointedModel, pointedModelAsProp, recursive)
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitDotNotation(model string) (string, []string) {
|
func splitDotNotation(model string) (string, []string) {
|
||||||
@ -103,12 +103,12 @@ func getField(model *swagger.NamedModel, sField string) (*swagger.NamedModelProp
|
|||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func printModelInfo(w io.Writer, model *swagger.NamedModel, modelProp *swagger.NamedModelProperty) error {
|
func printModelInfo(w io.Writer, model *swagger.NamedModel, modelProp *swagger.NamedModelProperty, recursive bool) error {
|
||||||
t, _ := getFieldType(&modelProp.Property)
|
t, _ := getFieldType(&modelProp.Property)
|
||||||
fmt.Fprintf(w, "RESOURCE: %s <%s>\n\n", modelProp.Name, t)
|
fmt.Fprintf(w, "RESOURCE: %s <%s>\n\n", modelProp.Name, t)
|
||||||
fieldDesc, _ := wrapAndIndentText(modelProp.Property.Description, " ", 80)
|
fieldDesc, _ := wrapAndIndentText(modelProp.Property.Description, " ", 80)
|
||||||
fmt.Fprintf(w, "DESCRIPTION:\n%s\n\n%s\n", fieldDesc, indentText(model.Model.Description, " "))
|
fmt.Fprintf(w, "DESCRIPTION:\n%s\n\n%s\n", fieldDesc, indentText(model.Model.Description, " "))
|
||||||
return printFields(w, model)
|
return printFields(w, model, recursive)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPrimitive(w io.Writer, field *swagger.NamedModelProperty) error {
|
func printPrimitive(w io.Writer, field *swagger.NamedModelProperty) error {
|
||||||
@ -119,12 +119,12 @@ func printPrimitive(w io.Writer, field *swagger.NamedModelProperty) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTopLevelResourceInfo(w io.Writer, model *swagger.NamedModel) error {
|
func printTopLevelResourceInfo(w io.Writer, model *swagger.NamedModel, recursive bool) error {
|
||||||
fmt.Fprintf(w, "DESCRIPTION:\n%s\n", model.Model.Description)
|
fmt.Fprintf(w, "DESCRIPTION:\n%s\n", model.Model.Description)
|
||||||
return printFields(w, model)
|
return printFields(w, model, recursive)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printFields(w io.Writer, model *swagger.NamedModel) error {
|
func printFields(w io.Writer, model *swagger.NamedModel, recursive bool) error {
|
||||||
fmt.Fprint(w, "\nFIELDS:\n")
|
fmt.Fprint(w, "\nFIELDS:\n")
|
||||||
for _, field := range model.Model.Properties.List {
|
for _, field := range model.Model.Properties.List {
|
||||||
fieldType, err := getFieldType(&field.Property)
|
fieldType, err := getFieldType(&field.Property)
|
||||||
|
Loading…
Reference in New Issue
Block a user