Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 32104df

Browse files
authoredMay 9, 2023
Merge pull request #1500 from merico-dev/new-dtm
Fix `dtm commit` Command Cannot Get The Message From -m Flag
2 parents a9a96c3 + 47f8b4f commit 32104df

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed
 

‎cmd/commit.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"os"
55

66
"github.com/spf13/cobra"
7-
"github.com/spf13/viper"
87

98
"github.com/devstream-io/devstream/internal/log"
109
"github.com/devstream-io/devstream/internal/pkg/commit"
1110
"github.com/devstream-io/devstream/internal/response"
1211
)
1312

13+
// commit message got from the command line by -m flag
14+
var message string
15+
1416
// commitCmd represents the commit command
1517
var commitCmd = &cobra.Command{
1618
Use: "commit",
@@ -22,9 +24,11 @@ e.g.
2224
1. dtm commit -m "commit message"
2325
`,
2426
Run: func(cmd *cobra.Command, args []string) {
25-
message := viper.GetString("message")
2627
if message == "" {
27-
log.Error("message is required")
28+
errStr := "message is required"
29+
log.Error(errStr)
30+
r := response.New(response.StatusError, response.MessageError, errStr)
31+
r.Print(OutputFormat)
2832
os.Exit(1)
2933
}
3034
err := commit.Commit(message)
@@ -41,5 +45,5 @@ e.g.
4145

4246
func init() {
4347
rootCmd.AddCommand(commitCmd)
44-
commitCmd.Flags().StringP("message", "m", "", "commit message")
48+
commitCmd.Flags().StringVarP(&message, "message", "m", "", "commit message")
4549
}

‎cmd/patch.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ e.g.
2626
`,
2727
Run: func(cmd *cobra.Command, args []string) {
2828
if len(args) != 1 {
29-
log.Error("Incorrect number of arguments")
29+
errMsg := "Incorrect number of arguments"
30+
log.Error(errMsg)
31+
r := response.New(response.StatusError, response.MessageError, errMsg)
32+
r.Print(OutputFormat)
3033
os.Exit(1)
3134
}
3235
err := patch.Patch(args[0])

‎cmd/root.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"os"
66

77
"github.com/sirupsen/logrus"
8-
9-
"github.com/devstream-io/devstream/internal/log"
10-
118
"github.com/spf13/cobra"
129
"github.com/spf13/viper"
1310

11+
"github.com/devstream-io/devstream/internal/log"
1412
"github.com/devstream-io/devstream/internal/option"
1513
)
1614

0 commit comments

Comments
 (0)
Please sign in to comment.