Skip to content
Snippets Groups Projects
Commit aa98218f authored by Jessica Yuen's avatar Jessica Yuen
Browse files

Clarify errors for commands requiring subcommands


Currently, commands such as `ks env non-existent-subcommand` will output
an error `Command 'env' requires a subcommand`.

This is not helpful since the user may assume there is the subcommand
'non-existent-subcommand'. This commit will clarify the error messages
in this scenario.

Signed-off-by: default avatarJessica Yuen <im.jessicayuen@gmail.com>
parent b91b432d
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ package cmd
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
......@@ -90,6 +91,9 @@ uniquely identifies the cluster.
staging.jsonnet
params.libsonnet`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("%s is not a valid subcommand\n\n%s", strings.Join(args, " "), cmd.UsageString())
}
return fmt.Errorf("Command 'env' requires a subcommand\n\n%s", cmd.UsageString())
},
}
......
......@@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
......@@ -58,6 +59,9 @@ run:
ks env --help
`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("%s is not a valid subcommand\n\n%s", strings.Join(args, " "), cmd.UsageString())
}
return fmt.Errorf("Command 'param' requires a subcommand\n\n%s", cmd.UsageString())
},
}
......
......@@ -44,6 +44,9 @@ var pkgCmd = &cobra.Command{
Use: "pkg",
Short: `Manage packages and dependencies for the current ksonnet project`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("%s is not a valid subcommand\n\n%s", strings.Join(args, " "), cmd.UsageString())
}
return fmt.Errorf("Command 'pkg' requires a subcommand\n\n%s", cmd.UsageString())
},
}
......
......@@ -44,6 +44,9 @@ var prototypeCmd = &cobra.Command{
Use: "prototype",
Short: `Instantiate, inspect, and get examples for ksonnet prototypes`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("%s is not a valid subcommand\n\n%s", strings.Join(args, " "), cmd.UsageString())
}
return fmt.Errorf("Command 'prototype' requires a subcommand\n\n%s", cmd.UsageString())
},
Long: `Manage, inspect, instantiate, and get examples for ksonnet prototypes.
......
......@@ -20,6 +20,9 @@ var registryCmd = &cobra.Command{
Use: "registry",
Short: `Manage registries for current project`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("%s is not a valid subcommand\n\n%s", strings.Join(args, " "), cmd.UsageString())
}
return fmt.Errorf("Command 'registry' requires a subcommand\n\n%s", cmd.UsageString())
},
Long: `Manage and inspect ksonnet registries.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment