Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions cmd/devstream/develop.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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")
}
5 changes: 4 additions & 1 deletion cmd/devstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions internal/pkg/develop/develop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}