-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (78 loc) · 2.54 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
p "github.io/iamthen0ise/bb/src/parsing"
s "github.io/iamthen0ise/bb/src/screen"
)
func main() {
var (
inputArgs = p.InputArgs{}
gitBranchName = p.GitBranchName{}
)
flag.String("i", "", "JIRA Link or issue")
flag.String("t", "", "Custom Issue Text")
flag.Bool("f", false, "Set `feature` prefix")
flag.Bool("h", false, "Set `hotfix` prefix")
flag.Bool("m", false, "Rename current branch instead of creating new")
flag.Bool("y", false, "Create and checkout without confirmation")
flag.Bool("commit", false, "Commit changes with prefixed message from branch name (default `false`")
flag.Bool("c", true, "Checkout to new branch (default `true`")
flag.Parse()
if len(os.Args) > 1 {
inputArgs.ParseArgs(os.Args[1:])
gitBranchName.UpdateFields(inputArgs.Prefix, inputArgs.IssueID, inputArgs.CustomTextParts)
} else {
inputScanner := bufio.NewScanner(os.Stdin)
var promptDefault = "Enter JIRA Issue link or some text. Press Enter once to submit or twice when ready > "
var promptCurrentLine = &gitBranchName.BranchName
fmt.Print(s.SavePosition)
for {
fmt.Print(s.RestorePosition, s.EraseLineToEnd)
if len(*promptCurrentLine) > 0 {
fmt.Print("Branch Name is: ", s.Colorize(promptCurrentLine, s.Yellow), " [Enter to finish] > ")
} else {
fmt.Print(s.Colorize(&promptDefault, s.Yellow), " ")
}
inputScanner.Scan()
text := inputScanner.Text()
inputArgs.ParseArgs(strings.Fields(text))
if len(text) == 0 {
break
}
gitBranchName.UpdateFields(inputArgs.Prefix, inputArgs.IssueID, inputArgs.CustomTextParts)
}
}
if inputArgs.ForceCreate {
err := gitBranchName.CreateBranch(true)
if err != nil {
fmt.Print("Can't create new branch,", err.Error())
}
} else {
fmt.Println("Your new branch name is:", s.Colorize(&gitBranchName.BranchName, s.Magenta))
if inputArgs.Strategy == "Rename" {
fmt.Println("Do you want to continue and rename current branch ? [Enter to continue]")
} else {
fmt.Println("Do you want to continue and create branch? [Enter to continue]")
}
scannerCreateBranch := bufio.NewScanner(os.Stdin)
scannerCreateBranch.Scan()
switch strings.ToLower(scannerCreateBranch.Text()) {
case "":
if inputArgs.Strategy == "Rename" {
err := gitBranchName.RenameCurrentBranch()
if err != nil {
fmt.Print("Can't rename current branch,", err.Error())
}
} else {
err := gitBranchName.CreateBranch(true)
if err != nil {
fmt.Print("Can't create new branch,", err.Error())
}
}
}
}
}