improve some error messages.

This commit is contained in:
Brendan Burns
2016-08-29 22:27:22 -07:00
parent 956501b1f0
commit 155fb9f4be
4 changed files with 39 additions and 13 deletions

View File

@@ -48,6 +48,10 @@ var (
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il`)
)
const (
execUsageStr = "expected 'exec <pod-name> <command> [arg1] [arg2] ... [argN]'.\n<pod-name> and <command> are required parameter for the exec command"
)
func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
options := &ExecOptions{
StreamOptions: StreamOptions{
@@ -135,19 +139,19 @@ type ExecOptions struct {
func (p *ExecOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
// Let kubectl exec follow rules for `--`, see #13004 issue
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
return cmdutil.UsageError(cmd, "POD is required for exec")
return cmdutil.UsageError(cmd, execUsageStr)
}
if len(p.PodName) != 0 {
printDeprecationWarning("exec POD", "-p POD")
printDeprecationWarning("exec <pod-name>", "-p <pod-name>")
if len(argsIn) < 1 {
return cmdutil.UsageError(cmd, "COMMAND is required for exec")
return cmdutil.UsageError(cmd, execUsageStr)
}
p.Command = argsIn
} else {
p.PodName = argsIn[0]
p.Command = argsIn[1:]
if len(p.Command) < 1 {
return cmdutil.UsageError(cmd, "COMMAND is required for exec")
return cmdutil.UsageError(cmd, execUsageStr)
}
}