diff --git a/tour/cmd/dynamodb.go b/tour/cmd/dynamodb.go index 8e678d7f..43bb7808 100644 --- a/tour/cmd/dynamodb.go +++ b/tour/cmd/dynamodb.go @@ -16,9 +16,11 @@ var dynamoLongDesc = strings.Join([]string{ }, "\n") var dynamoCmd = &cobra.Command{ - Use: "dynamo", - Short: "dynamodb to golang struct and base repository", - Long: dynamoLongDesc, + Use: "dynamo", + Short: "dynamodb to golang struct and base repository", + Long: dynamoLongDesc, + ValidArgs: []string{"generate"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { log.Printf("dynamo have no commands named %s, plaese use dynamo --help to see detail", strings.Join(args, ",")) diff --git a/tour/cmd/mongodb.go b/tour/cmd/mongodb.go index fcd55eb7..852849cf 100644 --- a/tour/cmd/mongodb.go +++ b/tour/cmd/mongodb.go @@ -16,9 +16,11 @@ var mongoLongDesc = strings.Join([]string{ }, "\n") var mongoCmd = &cobra.Command{ - Use: "mongo", - Short: "mongodb to golang struct and base repository", - Long: mongoLongDesc, + Use: "mongo", + Short: "mongodb to golang struct and base repository", + Long: mongoLongDesc, + ValidArgs: []string{"generate"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { log.Printf("mongo have no commands named %s, plaese use mongo --help to see detail", strings.Join(args, ",")) diff --git a/tour/cmd/openapi.go b/tour/cmd/openapi.go index a7809e10..d98418ec 100644 --- a/tour/cmd/openapi.go +++ b/tour/cmd/openapi.go @@ -12,13 +12,12 @@ import ( ) var openapiCmd = &cobra.Command{ - Use: "openapi", - Short: "openapi generate", - Long: "openapi generate", + Use: "openapi", + Short: "openapi generate", + Long: "openapi generate", + ValidArgs: []string{"generate", "swag2openapi"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { - if len(args) > 0 { - log.Printf("openapi have no commands named %s, plaese use openapi --help to see detail", strings.Join(args, ",")) - } }, } diff --git a/tour/cmd/root.go b/tour/cmd/root.go index 58a5407b..4c4a6f45 100644 --- a/tour/cmd/root.go +++ b/tour/cmd/root.go @@ -5,9 +5,11 @@ import ( ) var rootCmd = &cobra.Command{ - Use: "", - Short: "", - Long: "", + Use: "", + Short: "", + Long: "", + ValidArgs: []string{"dynamo", "mongo", "openapi", "sql", "time", "word"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { }, diff --git a/tour/cmd/sql.go b/tour/cmd/sql.go index 0aaa03f5..65bb1252 100644 --- a/tour/cmd/sql.go +++ b/tour/cmd/sql.go @@ -8,10 +8,12 @@ import ( ) var sqlCmd = &cobra.Command{ - Use: "sql", - Short: "sql", - Long: "sql", - Run: func(cmd *cobra.Command, Args []string) {}, + Use: "sql", + Short: "sql", + Long: "sql", + ValidArgs: []string{"struct"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + Run: func(cmd *cobra.Command, Args []string) {}, } var sql2structCmd = &cobra.Command{ diff --git a/tour/cmd/time.go b/tour/cmd/time.go index 78aeff9a..f1a2a16a 100644 --- a/tour/cmd/time.go +++ b/tour/cmd/time.go @@ -11,9 +11,11 @@ import ( ) var timeCmd = &cobra.Command{ - Use: "time", - Short: "time format", - Long: "time format", + Use: "time", + Short: "time format", + Long: "time format", + ValidArgs: []string{"now", "calc"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { // nowTime := timer.GetNowTime() // log.Printf("output %s, %d", nowTime.Format("2006-01-02 15:04:05"), nowTime.Unix()) diff --git a/tour/cmd/word.go b/tour/cmd/word.go index 9c34c92b..77a724a8 100644 --- a/tour/cmd/word.go +++ b/tour/cmd/word.go @@ -23,6 +23,7 @@ var wordCmd = &cobra.Command{ Use: "word", Short: "change word", Long: desc, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { var content string switch mode {