-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd_delete.go
61 lines (57 loc) · 1.16 KB
/
cmd_delete.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"gita/exec"
"strings"
cli "github.com/urfave/cli/v2"
)
var cmdDelete = &cli.Command{
Name: "delete",
Aliases: []string{},
Usage: "delete branch.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "confirm",
Usage: "confirm operation. true",
Required: true,
},
&cli.StringFlag{
Name: "branch",
Usage: "branch to delete",
Required: true,
},
&cli.BoolFlag{
Name: "remote",
Usage: "remove remote branch",
Required: false,
},
&cli.BoolFlag{
Name: "force",
Usage: "force operate",
Required: false,
},
},
Description: `
git branch -d <branch>
`,
Action: func(c *cli.Context) error {
if confirm := c.String("confirm"); confirm != "true" {
return fmt.Errorf("invalid confirm text %s, expect true", confirm)
}
cmd := ""
branch := c.String("branch")
switch {
case c.Bool("remote"):
cmd = fmt.Sprintf("git branch -r -d origin/%s", branch)
default:
cmd = fmt.Sprintf("git branch -d %s", branch)
}
if c.Bool("force") {
cmd = strings.Replace(cmd, "-d", "-D", 1)
}
if err := exec.ShellExecute(cmd); err != nil {
return err
}
return nil
},
}