-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.go
41 lines (35 loc) · 919 Bytes
/
commit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dx
import (
"fmt"
"log/slog"
"github.com/kitimark/dx/pkg/exec"
"github.com/spf13/cobra"
"go.mongodb.org/mongo-driver/v2/bson"
)
func NewCommitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "commit [flags]",
Example: "commit -m \"commit message\"",
Args: cobra.NoArgs,
RunE: cmdCommitRun,
}
cmd.PersistentFlags().StringP("message", "m", "", "message")
err := cmd.MarkPersistentFlagRequired("message")
if err != nil {
panic(err)
}
return cmd
}
func cmdCommitRun(cmd *cobra.Command, _ []string) error {
flags := cmd.Flags()
message, err := flags.GetString("message")
if err != nil {
return err
}
slog.Info("args", slog.String("message", message))
changeId := bson.NewObjectID().Hex()
changeIdMessage := fmt.Sprintf("change-id: %s", changeId)
args := []string{"commit", "-m", message, "-m", changeIdMessage}
_, err = exec.OutputErr("git", args...)
return err
}