github.com/fsmiamoto/ck@v0.0.2-0.20200603013204-6b305c3a6c30/cmd/ck/main.go (about) 1 package main 2 3 import ( 4 "log" 5 "os" 6 7 "github.com/fsmiamoto/ck/git" 8 "github.com/ktr0731/go-fuzzyfinder" 9 ) 10 11 func main() { 12 path := "." 13 14 if len(os.Args) > 1 { 15 path = os.Args[1] 16 } 17 18 if err := run(path); err != nil { 19 log.Fatal(err) 20 } 21 } 22 23 func run(path string) error { 24 repo, err := git.OpenRepository(path) 25 if err != nil { 26 log.Fatal(err) 27 } 28 29 branches, err := repo.Branches() 30 if err != nil { 31 log.Fatal(err) 32 } 33 34 index, err := fuzzyfinder.Find(branches, func(i int) string { 35 return branches[i] 36 }, fuzzyfinder.WithPromptString("Checkout: ")) 37 38 if err != nil { 39 log.Fatal(err) 40 } 41 42 return repo.Checkout(branches[index]) 43 }