Skip to content

Commit

Permalink
feat(sync): allow continue sync when code conflict (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitimark authored Oct 12, 2024
1 parent 470a4ad commit 5a616ae
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 91 deletions.
19 changes: 19 additions & 0 deletions base32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dx

import "encoding/base32"

var b32encoding *base32.Encoding

func init() {
b32encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567").
WithPadding(base32.NoPadding)
}

func b32en(name string) string {
return b32encoding.EncodeToString([]byte(name))
}

func b32de(encode string) (string, error) {
b, err := b32encoding.DecodeString(encode)
return string(b), err
}
3 changes: 2 additions & 1 deletion cmd/dx/dx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

func main() {
err := dx.Main.Execute()
cmd := dx.NewMainCmd()
err := cmd.Execute()
if err != nil {
slog.Info(err.Error())
os.Exit(2)
Expand Down
20 changes: 11 additions & 9 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import (
"go.mongodb.org/mongo-driver/v2/bson"
)

var CmdCommit = &cobra.Command{
Use: "commit [flags]",
Example: "commit -m \"commit message\"",
Args: cobra.NoArgs,
RunE: cmdCommitRun,
}
func NewCommitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "commit [flags]",
Example: "commit -m \"commit message\"",
Args: cobra.NoArgs,
RunE: cmdCommitRun,
}

func init() {
CmdCommit.PersistentFlags().StringP("message", "m", "", "message")
err := CmdCommit.MarkPersistentFlagRequired("message")
cmd.PersistentFlags().StringP("message", "m", "", "message")
err := cmd.MarkPersistentFlagRequired("message")
if err != nil {
panic(err)
}

return cmd
}

func cmdCommitRun(cmd *cobra.Command, _ []string) error {
Expand Down
19 changes: 11 additions & 8 deletions dx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"github.com/spf13/cobra"
)

var Main = &cobra.Command{
Use: "dx [flags] [command]",
PersistentPreRunE: cmdMainPreRun,
}
func NewMainCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "dx [flags] [command]",
PersistentPreRunE: cmdMainPreRun,
}

cmd.PersistentFlags().BoolP("debug", "d", false, "print debug info")

cmd.AddCommand(NewCommitCmd())
cmd.AddCommand(NewSyncCmd())

func init() {
Main.PersistentFlags().BoolP("debug", "d", false, "print debug info")
Main.AddCommand(CmdCommit)
Main.AddCommand(CmdSync)
return cmd
}

func cmdMainPreRun(cmd *cobra.Command, _ []string) error {
Expand Down
Loading

0 comments on commit 5a616ae

Please sign in to comment.