From 8f0bd7a67c180ca0a186ae5651ea2d6f402eadc7 Mon Sep 17 00:00:00 2001 From: hxcGit Date: Thu, 19 May 2022 15:20:46 +0800 Subject: [PATCH 1/3] refactor: modify args to subcommand in dtm list --- cmd/devstream/list.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/devstream/list.go b/cmd/devstream/list.go index 1f7c3c49c..270ccf4dc 100644 --- a/cmd/devstream/list.go +++ b/cmd/devstream/list.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/cmd/devstream/list" ) @@ -16,27 +12,25 @@ var ( var listCMD = &cobra.Command{ Use: "list", - Short: "This command lists all of the plugins", + Short: "This command only supports listing plugins now.", +} + +var listPluginsCMD = &cobra.Command{ + Use: "plugins", + Short: "List all plugins", Long: `This command lists all of the plugins. Examples: dtm list plugins`, - Run: options.WithValidators(listCMDFunc, options.ArgsCountEqual(1), validateListCMDArgs), + Run: listPluginsCMDFunc, } -func listCMDFunc(cmd *cobra.Command, args []string) { +func listPluginsCMDFunc(cmd *cobra.Command, args []string) { list.List(pluginFilter) } -func validateListCMDArgs(args []string) error { - // only support "plugins" now - - if args[0] != "plugins" { - return fmt.Errorf("arg should be \"plugins\" only") - } - return nil -} - // TODO Use `--group=somegroup` to filter the specified groups on feature func init() { - listCMD.PersistentFlags().StringVarP(&pluginFilter, "filter", "r", "", "filter plugin by regex") + listCMD.AddCommand(listPluginsCMD) + + listPluginsCMD.PersistentFlags().StringVarP(&pluginFilter, "filter", "r", "", "filter plugin by regex") } From a15825ee6874b483d3fec0fc8d11b70f03cbdcae Mon Sep 17 00:00:00 2001 From: hxcGit Date: Thu, 19 May 2022 15:24:46 +0800 Subject: [PATCH 2/3] style: modify tab to two spaces in examples --- cmd/devstream/develop.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/devstream/develop.go b/cmd/devstream/develop.go index f2d2a5f08..eeac6d5ae 100644 --- a/cmd/devstream/develop.go +++ b/cmd/devstream/develop.go @@ -22,7 +22,7 @@ var developCreatePluginCMD = &cobra.Command{ Short: "Create a new plugin", Long: `Create-plugin is used for creating a new plugin. Exampls: - dtm develop create-plugin --name=YOUR-PLUGIN-NAME`, + dtm develop create-plugin --name=YOUR-PLUGIN-NAME`, Run: developCreateCMDFunc, } @@ -31,8 +31,8 @@ var developValidatePluginCMD = &cobra.Command{ Short: "Validate a plugin", Long: `Validate-plugin is used for validating an existing plugin or all plugins. Examples: - dtm develop validate-plugin --name=YOUR-PLUGIN-NAME, - dtm develop validate-plugin --all`, + dtm develop validate-plugin --name=YOUR-PLUGIN-NAME, + dtm develop validate-plugin --all`, Run: developValidateCMDFunc, } From 3b9aa484d0e58c589bb36536743aefc00a2d1461 Mon Sep 17 00:00:00 2001 From: hxcGit Date: Thu, 19 May 2022 16:57:07 +0800 Subject: [PATCH 3/3] refactor: modify args to subcommand in dtm show --- cmd/devstream/main.go | 5 +++- cmd/devstream/show.go | 53 ++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/cmd/devstream/main.go b/cmd/devstream/main.go index 5fb3bd27f..a354b6a35 100644 --- a/cmd/devstream/main.go +++ b/cmd/devstream/main.go @@ -84,7 +84,10 @@ func initConfig() { if err := viper.BindPFlags(developValidatePluginCMD.Flags()); err != nil { log.Fatal(err) } - if err := viper.BindPFlags(showCMD.Flags()); err != nil { + if err := viper.BindPFlags(showConfigCMD.Flags()); err != nil { + log.Fatal(err) + } + if err := viper.BindPFlags(showStatusCMD.Flags()); err != nil { log.Fatal(err) } } diff --git a/cmd/devstream/show.go b/cmd/devstream/show.go index 453bb4601..44484759f 100644 --- a/cmd/devstream/show.go +++ b/cmd/devstream/show.go @@ -1,13 +1,10 @@ package main import ( - "fmt" - "github.com/spf13/cobra" - "github.com/devstream-io/devstream/cmd/devstream/options" - - "github.com/devstream-io/devstream/internal/pkg/show" + "github.com/devstream-io/devstream/internal/pkg/show/config" + "github.com/devstream-io/devstream/internal/pkg/show/status" "github.com/devstream-io/devstream/pkg/util/log" ) @@ -15,34 +12,48 @@ var plugin string var instanceName string var showCMD = &cobra.Command{ - Use: "show [config | status]", + Use: "show", Short: "Show is used to print some useful information", - Long: `Show is used to print some useful information. +} + +var showConfigCMD = &cobra.Command{ + Use: "config", + Short: "Show configuration information", + Long: `Show config is used for showing plugins' template configuration information. +Examples: + dtm show config --plugin=A-PLUGIN-NAME`, + Run: showConfigCMDFunc, +} + +var showStatusCMD = &cobra.Command{ + Use: "status", + Short: "Show status information", + Long: `Show status is used for showing plugins' status information. Examples: - dtm show config --plugin=A-PLUGIN-NAME dtm show status --plugin=A-PLUGIN-NAME --name=A-PLUGIN-INSTANCE-NAME dtm show status -p=A-PLUGIN-NAME -n=A-PLUGIN-INSTANCE-NAME`, - Run: options.WithValidators(showCMDFunc, options.ArgsCountEqual(1), validateShowArgs), + Run: showStatusCMDFunc, } -func showCMDFunc(cmd *cobra.Command, args []string) { - showInfo := show.Info(args[0]) - log.Debugf("The show info is: %s.", showInfo) - if err := show.GenerateInfo(configFile, showInfo); err != nil { +func showConfigCMDFunc(cmd *cobra.Command, args []string) { + log.Debug("Show configuration information.") + if err := config.Show(); err != nil { log.Fatal(err) } } -func validateShowArgs(args []string) error { - // arg is "config" or "status" here, maybe will have "output" in the future. - showInfo := show.Info(args[0]) - if !show.IsValideInfo(showInfo) { - return fmt.Errorf("invalide Show Info") +func showStatusCMDFunc(cmd *cobra.Command, args []string) { + log.Debug("Show status information.") + if err := status.Show(configFile); err != nil { + log.Fatal(err) } - return nil } func init() { - showCMD.PersistentFlags().StringVarP(&plugin, "plugin", "p", "", "specify name with the plugin") - showCMD.PersistentFlags().StringVarP(&instanceName, "name", "n", "", "specify name with the plugin instance") + showCMD.AddCommand(showConfigCMD) + showCMD.AddCommand(showStatusCMD) + + showConfigCMD.PersistentFlags().StringVarP(&plugin, "plugin", "p", "", "specify name with the plugin") + showStatusCMD.PersistentFlags().StringVarP(&plugin, "plugin", "p", "", "specify name with the plugin") + showStatusCMD.PersistentFlags().StringVarP(&instanceName, "name", "n", "", "specify name with the plugin instance") }