-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (58 loc) · 1.04 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
package main
import (
"flag"
"log"
"os"
"runtime/debug"
tui "github.com/manifoldco/promptui"
)
var (
pipeline bool
version bool
)
func init() {
flag.BoolVar(&pipeline, "p", false, "open github action page or gitlab pipeline page")
flag.BoolVar(&version, "v", false, "show program version")
flag.Parse()
if version {
printVersion()
os.Exit(0)
}
}
func main() {
origins, err := GitRemotes()
if err != nil {
log.Fatal(err)
}
if err := OpenWithSelect(origins); err != nil {
log.Fatal(err)
}
}
func OpenWithSelect(origins []string) error {
if len(origins) > 1 {
prompt := tui.Select{
Label: "Select a remote address",
Items: origins,
}
_, origin, err := prompt.Run()
if err != nil {
log.Fatalf("Prompt failed %v\n", err)
return err
}
if pipeline {
return Open(WithPipeline(origin))
}
return Open(origin)
} else {
if pipeline {
return Open(WithPipeline(origins[0]))
}
return Open(origins[0])
}
}
func printVersion() {
info, ok := debug.ReadBuildInfo()
if ok {
println(info.Main.Version)
}
}