Move printing the valid resource types to a function

Should be calculated from discovery in the future. Also improve
descriptions on the affected commands.
This commit is contained in:
Clayton Coleman
2017-10-23 21:14:31 -04:00
parent 55fdceca93
commit 93fed120fb
12 changed files with 305 additions and 97 deletions

View File

@@ -32,9 +32,15 @@ import (
var (
explainLong = templates.LongDesc(`
Documentation of resources.
` + validResources)
List the fields for supported resources
This command describes the fields associated with each supported API resource.
Fields are identified via a simple JSONPath identifier:
<type>.<fieldName>[.<fieldName>]
Add the --recursive flag to display all of the fields at once without descriptions.
Information about each field is retrieved from the server in OpenAPI format.`)
explainExamples = templates.Examples(i18n.T(`
# Get the documentation of the resource and its fields
@@ -49,7 +55,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "explain RESOURCE",
Short: i18n.T("Documentation of resources"),
Long: explainLong,
Long: explainLong + "\n\n" + cmdutil.ValidResourceTypeList(f),
Example: explainExamples,
Run: func(cmd *cobra.Command, args []string) {
err := RunExplain(f, out, cmdErr, cmd, args)
@@ -65,7 +71,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
// RunExplain executes the appropriate steps to print a model's documentation
func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
fmt.Fprintf(cmdErr, "You must specify the type of resource to explain. %s\n", validResources)
fmt.Fprintf(cmdErr, "You must specify the type of resource to explain. %s\n", cmdutil.ValidResourceTypeList(f))
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
}
if len(args) > 1 {