Skip to content

Commit

Permalink
Merge pull request #1500 from merico-dev/new-dtm
Browse files Browse the repository at this point in the history
Fix `dtm commit` Command Cannot Get The Message From -m Flag
  • Loading branch information
daniel-hutao committed May 9, 2023
2 parents a9a96c3 + 47f8b4f commit 32104df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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")
}
5 changes: 4 additions & 1 deletion cmd/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 32104df

Please sign in to comment.