-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.go
46 lines (40 loc) · 1.01 KB
/
print.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
package list
import (
"fmt"
"github.com/aerfio/gobc/internal/githandler"
"github.com/jedib0t/go-pretty/list"
)
func getBranches() (local, remote []interface{}, err error) {
localRef, remoteRef, err := githandler.GetBranches()
if err != nil {
return nil, nil, err
}
localBranches, remoteBranches := make([]interface{}, 0), make([]interface{}, 0)
for _, loc := range *localRef {
localBranches = append(localBranches, loc.Name().Short())
}
for _, rem := range *remoteRef {
remoteBranches = append(remoteBranches, rem.Name().Short())
}
return localBranches, remoteBranches, nil
}
// Print prints tree which shows your local and remote branches in pretty format
func Print() error {
local, remote, err := getBranches()
if err != nil {
return err
}
l := list.NewWriter()
l.SetStyle(list.StyleDefault)
l.Indent()
l.AppendItem("local")
l.Indent()
l.AppendItems(local)
l.UnIndent()
l.AppendItem("origin")
l.Indent()
l.AppendItems(remote)
fmt.Println("Branches:")
fmt.Println(l.Render())
return nil
}