-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (45 loc) · 1.17 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/rm3l/gh-dev-branch/pkg/branch"
"github.com/rm3l/gh-dev-branch/pkg/issue"
)
func main() {
var repo string
var maxLen int
flag.StringVar(&repo, "repo", "", "repository to use for finding the issue")
flag.IntVar(&maxLen, "max-length", -1, "max length of generated branch name")
flag.Usage = func() {
//goland:noinspection GoUnhandledErrorResult
fmt.Fprintln(os.Stderr, "Usage: gh dev-branch <issue> [options]")
fmt.Println("Options: ")
flag.PrintDefaults()
}
if len(os.Args) < 2 {
//goland:noinspection GoUnhandledErrorResult
fmt.Fprintln(os.Stderr, "missing issue")
flag.Usage()
os.Exit(1)
}
iss := os.Args[1]
if iss == "-h" || iss == "-help" || iss == "--help" {
flag.Usage()
os.Exit(1)
} else {
// Ignore errors since flag.CommandLine is set for ExitOnError.
_ = flag.CommandLine.Parse(os.Args[2:])
}
ghIssueFinder := issue.NewGHIssueFinder()
issueInfo, err := ghIssueFinder.FindById(os.Stderr, repo, iss)
if err != nil {
log.Fatalln(err)
}
branchName, err := branch.GenerateName(issueInfo.Id, issueInfo.Title, maxLen)
if err != nil {
log.Fatalln(err)
}
fmt.Println(branchName)
}