From 47f8b4fc42aa3543c5e72af02ab668f9b5a197d1 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Tue, 9 May 2023 10:39:52 +0800 Subject: [PATCH] fix: dtm commit command cannot get the message from -m flag Signed-off-by: Daniel Hu --- cmd/commit.go | 12 ++++++++---- cmd/patch.go | 5 ++++- cmd/root.go | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/commit.go b/cmd/commit.go index e959dd067..6bf840e6d 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -4,13 +4,15 @@ import ( "os" "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/devstream-io/devstream/internal/log" "github.com/devstream-io/devstream/internal/pkg/commit" "github.com/devstream-io/devstream/internal/response" ) +// commit message got from the command line by -m flag +var message string + // commitCmd represents the commit command var commitCmd = &cobra.Command{ Use: "commit", @@ -22,9 +24,11 @@ e.g. 1. dtm commit -m "commit message" `, Run: func(cmd *cobra.Command, args []string) { - message := viper.GetString("message") if message == "" { - log.Error("message is required") + errStr := "message is required" + log.Error(errStr) + r := response.New(response.StatusError, response.MessageError, errStr) + r.Print(OutputFormat) os.Exit(1) } err := commit.Commit(message) @@ -41,5 +45,5 @@ e.g. func init() { rootCmd.AddCommand(commitCmd) - commitCmd.Flags().StringP("message", "m", "", "commit message") + commitCmd.Flags().StringVarP(&message, "message", "m", "", "commit message") } diff --git a/cmd/patch.go b/cmd/patch.go index 0083ac163..d03ebd325 100644 --- a/cmd/patch.go +++ b/cmd/patch.go @@ -26,7 +26,10 @@ e.g. `, Run: func(cmd *cobra.Command, args []string) { if len(args) != 1 { - log.Error("Incorrect number of arguments") + errMsg := "Incorrect number of arguments" + log.Error(errMsg) + r := response.New(response.StatusError, response.MessageError, errMsg) + r.Print(OutputFormat) os.Exit(1) } err := patch.Patch(args[0]) diff --git a/cmd/root.go b/cmd/root.go index 1322424c7..5f01a3954 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,12 +5,10 @@ import ( "os" "github.com/sirupsen/logrus" - - "github.com/devstream-io/devstream/internal/log" - "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/devstream-io/devstream/internal/log" "github.com/devstream-io/devstream/internal/option" )