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" )