diff --git a/cmd/devstream/develop.go b/cmd/devstream/develop.go index 6f5a97212..f2d2a5f08 100644 --- a/cmd/devstream/develop.go +++ b/cmd/devstream/develop.go @@ -1,12 +1,8 @@ package main import ( - "fmt" - "github.com/spf13/cobra" - "github.com/devstream-io/devstream/cmd/devstream/options" - "github.com/devstream-io/devstream/internal/pkg/develop" "github.com/devstream-io/devstream/pkg/util/log" ) @@ -19,31 +15,44 @@ var ( var developCMD = &cobra.Command{ Use: "develop", Short: "Develop is used for develop a new plugin", - Long: `Develop is used for develop a new plugin. +} + +var developCreatePluginCMD = &cobra.Command{ + Use: "create-plugin", + Short: "Create a new plugin", + Long: `Create-plugin is used for creating a new plugin. +Exampls: + dtm develop create-plugin --name=YOUR-PLUGIN-NAME`, + Run: developCreateCMDFunc, +} + +var developValidatePluginCMD = &cobra.Command{ + Use: "validate-plugin", + Short: "Validate a plugin", + Long: `Validate-plugin is used for validating an existing plugin or all plugins. Examples: - dtm develop create-plugin --name=YOUR-PLUGIN-NAME, - dtm develop validate-plugin --name=YOUR-PLUGIN-NAME`, - Run: options.WithValidators(developCMDFunc, options.ArgsCountEqual(1), validateDevelopArgs), + dtm develop validate-plugin --name=YOUR-PLUGIN-NAME, + dtm develop validate-plugin --all`, + Run: developValidateCMDFunc, } -func developCMDFunc(cmd *cobra.Command, args []string) { - developAction := develop.Action(args[0]) - log.Debugf("The develop action is: %s.", developAction) - if err := develop.ExecuteAction(developAction); err != nil { +func developCreateCMDFunc(cmd *cobra.Command, args []string) { + if err := develop.CreatePlugin(); err != nil { log.Fatal(err) } } -func validateDevelopArgs(args []string) error { - // "create-plugin" or "validate-plugin". Maybe it will be "delete-plugin"/"rename-plugin" in future. - developAction := develop.Action(args[0]) - if !develop.IsValideAction(developAction) { - return fmt.Errorf("invalide Develop Action") +func developValidateCMDFunc(cmd *cobra.Command, args []string) { + if err := develop.ValidatePlugin(); err != nil { + log.Fatal(err) } - return nil } func init() { - developCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name with the new plugin") - developCMD.PersistentFlags().BoolVarP(&all, "all", "a", false, "validate all plugins") + developCMD.AddCommand(developCreatePluginCMD) + developCMD.AddCommand(developValidatePluginCMD) + + developCreatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name with the new plugin") + developValidatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name with the new plugin") + developValidatePluginCMD.PersistentFlags().BoolVarP(&all, "all", "a", false, "validate all plugins") } diff --git a/cmd/devstream/main.go b/cmd/devstream/main.go index b7f9f65fa..5fb3bd27f 100644 --- a/cmd/devstream/main.go +++ b/cmd/devstream/main.go @@ -78,7 +78,10 @@ func initConfig() { if err := viper.BindPFlags(rootCMD.Flags()); err != nil { log.Fatal(err) } - if err := viper.BindPFlags(developCMD.Flags()); err != nil { + if err := viper.BindPFlags(developCreatePluginCMD.Flags()); err != nil { + log.Fatal(err) + } + if err := viper.BindPFlags(developValidatePluginCMD.Flags()); err != nil { log.Fatal(err) } if err := viper.BindPFlags(showCMD.Flags()); err != nil { diff --git a/internal/pkg/develop/develop.go b/internal/pkg/develop/develop.go index 3862f0aa6..6dc88c85c 100644 --- a/internal/pkg/develop/develop.go +++ b/internal/pkg/develop/develop.go @@ -22,15 +22,12 @@ func IsValideAction(action Action) bool { return ok } -func ExecuteAction(action Action) error { - switch action { - case ActionCreatePlugin: - log.Debugf("Action: %s.", ActionCreatePlugin) - return plugin.Create() - case ActionValidatePlugin: - log.Debugf("Action: %s.", ActionValidatePlugin) - return plugin.Validate() - default: - panic("This should be never happen!") - } +func CreatePlugin() error { + log.Debugf("Start create plugin") + return plugin.Create() +} + +func ValidatePlugin() error { + log.Debugf("Start validate plugin") + return plugin.Validate() }