/
branchesCmd.go
65 lines (54 loc) · 1.43 KB
/
branchesCmd.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
package main
import (
"flag"
"fmt"
"os"
"sort"
)
func branchesCmd(args []string) {
// command-line flags
fs := flag.NewFlagSet("branches", flag.ExitOnError)
help := fs.Bool("h", false, "show usage message")
verbose := fs.Bool("v", false, "more detailed output")
fs.Usage = func() { branchesUsage(fs) }
fs.Parse(args)
if *help {
fs.Usage()
os.Exit(0)
}
if fs.NArg() != 0 {
fs.Usage()
os.Exit(2)
}
config, err := loadBranchConfig()
must(err)
branches := config.branches
sort.Sort(byGitName{branches})
if !*verbose {
for _, v := range branches {
fmt.Println(v.Git)
}
} else {
for i, v := range branches {
if i != 0 {
fmt.Println("")
}
fmt.Printf("Git: %s\nUrl: %s\nBzr: %s\n", v.Git, v.Url, v.Bzr)
}
}
}
func branchesUsage(fs *flag.FlagSet) {
fmt.Println("usage: git-bzr-bridge branches [-h] [-v]")
fmt.Println("\nflags:")
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
fmt.Print(`
branches will list all branches known to git-bzr-bridge. Default output
format will list git branch references one per line. If -v is specified
it will also show Bzr urls and names of the (hidden) bzr branches.
`)
}
type byGitName struct{ branchList }
func (x byGitName) Less(i, j int) bool { return x.branchList[i].Git < x.branchList[j].Git }
func (x byGitName) Len() int { return len(x.branchList) }
func (x byGitName) Swap(i, j int) { x.branchList[i], x.branchList[j] = x.branchList[j], x.branchList[i] }