Skip to content

Commit

Permalink
feat: dev add arg length validate
Browse files Browse the repository at this point in the history
  • Loading branch information
fengcaiwen committed Oct 2, 2023
1 parent f314031 commit 6ca33ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cmd/kubevpn/cmds/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CmdDev(f cmdutil.Factory) *cobra.Command {
var transferImage bool
cmd := &cobra.Command{
Use: "dev TYPE/NAME [-c CONTAINER] [flags] -- [args...]",
Short: i18n.T("Startup your kubernetes workloads in local Docker container with same volume、env、and network"),
Short: i18n.T("Startup your kubernetes workloads in local Docker container"),
Long: templates.LongDesc(i18n.T(`
Startup your kubernetes workloads in local Docker container with same volume、env、and network
Expand Down Expand Up @@ -75,6 +75,15 @@ Startup your kubernetes workloads in local Docker container with same volume、e
Args: cobra.MatchAll(cobra.OnlyValidArgs),
DisableFlagsInUseLine: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
fmt.Fprintf(os.Stdout, "You must specify the type of resource to proxy. %s\n\n", cmdutil.SuggestAPIResources("kubevpn"))
fullCmdName := cmd.Parent().CommandPath()
usageString := "Required resource not specified."
if len(fullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "explain") {
usageString = fmt.Sprintf("%s\nUse \"%s explain <resource>\" for a detailed description of that resource (e.g. %[2]s explain pods).", usageString, fullCmdName)
}
return cmdutil.UsageErrorf(cmd, usageString)
}
err = cmd.Flags().Parse(args[1:])
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubevpn/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func NewKubeVPNCommand() *cobra.Command {
CmdConfig(factory),
CmdCp(factory),
CmdSSH(factory),
CmdLogs(factory),
CmdReset(factory),
CmdQuit(factory),
},
},
{
Message: "Other commands",
Commands: []*cobra.Command{
CmdLogs(factory),
CmdStatus(factory),
CmdVersion(factory),
CmdUpgrade(factory),
Expand Down

0 comments on commit 6ca33ca

Please sign in to comment.