-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 869 Bytes
/
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
package main
import (
"brunch/internal"
"fmt"
"github.com/spf13/cobra"
"os"
"os/exec"
)
var rootCmd = &cobra.Command{
Use: "brunch",
Short: "brunch displays all recent branches for a given git repository",
RunE: func(cmd *cobra.Command, args []string) error {
count, err := cmd.Flags().GetInt("count")
if err != nil {
return err
}
var displayObjects []internal.DisplayObject
displayObjects, err = internal.Brunch(count)
if err != nil {
return err
}
selected, err := internal.Prompt(displayObjects)
if err != nil {
return err
}
err = exec.Command("git", "checkout", selected).Run()
if err != nil {
return err
}
return nil
},
}
func main() {
rootCmd.Flags().IntP("count", "c", 8, "how many branches to display")
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}