diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-24 15:25:57 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-24 15:25:57 +0200 |
commit | 43bda202fa347e6893671b05376c0e4fcb9196f4 (patch) | |
tree | a542a6b7f593335df9950df16997c9b220bf4520 /commands | |
parent | 5e8fb7ec5058b816ccc9622f52dbf1777254656c (diff) | |
download | git-bug-43bda202fa347e6893671b05376c0e4fcb9196f4.tar.gz |
commands: add the "bridge" and "bridge configure" commands
Diffstat (limited to 'commands')
-rw-r--r-- | commands/bridge.go | 38 | ||||
-rw-r--r-- | commands/bridge_configure.go | 95 | ||||
-rw-r--r-- | commands/select/select_test.go | 3 |
3 files changed, 133 insertions, 3 deletions
diff --git a/commands/bridge.go b/commands/bridge.go new file mode 100644 index 00000000..93b5991b --- /dev/null +++ b/commands/bridge.go @@ -0,0 +1,38 @@ +package commands + +import ( + "fmt" + + "github.com/MichaelMure/git-bug/bridge" + "github.com/MichaelMure/git-bug/cache" + "github.com/spf13/cobra" +) + +func runBridge(cmd *cobra.Command, args []string) error { + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + configured, err := bridge.ConfiguredBridges(backend) + if err != nil { + return err + } + + for _, c := range configured { + fmt.Println(c) + } + + return nil +} + +var bridgeCmd = &cobra.Command{ + Use: "bridge", + Short: "Configure and use bridges to other bug trackers", + RunE: runBridge, +} + +func init() { + RootCmd.AddCommand(bridgeCmd) +} diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go new file mode 100644 index 00000000..564affcc --- /dev/null +++ b/commands/bridge_configure.go @@ -0,0 +1,95 @@ +package commands + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/MichaelMure/git-bug/bridge" + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/cache" + "github.com/spf13/cobra" +) + +func runBridgeConfigure(cmd *cobra.Command, args []string) error { + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + target, err := promptTarget() + if err != nil { + return err + } + + name, err := promptName() + if err != nil { + return err + } + + b, err := core.NewBridge(backend, target, name) + if err != nil { + return err + } + + err = b.Configure() + if err != nil { + return err + } + + return nil +} + +func promptTarget() (string, error) { + targets := bridge.Targets() + + for { + fmt.Printf("target (%s): ", strings.Join(targets, ",")) + + line, err := bufio.NewReader(os.Stdin).ReadString('\n') + if err != nil { + return "", err + } + + line = strings.TrimRight(line, "\n") + + for _, t := range targets { + if t == line { + return t, nil + } + } + + fmt.Println("invalid target") + } +} + +func promptName() (string, error) { + defaultName := "default" + + fmt.Printf("name [%s]: ", defaultName) + + line, err := bufio.NewReader(os.Stdin).ReadString('\n') + if err != nil { + return "", err + } + + line = strings.TrimRight(line, "\n") + + if line == "" { + return defaultName, nil + } + + return line, nil +} + +var bridgeConfigureCmd = &cobra.Command{ + Use: "configure", + Short: "Configure a new bridge", + RunE: runBridgeConfigure, +} + +func init() { + bridgeCmd.AddCommand(bridgeConfigureCmd) +} diff --git a/commands/select/select_test.go b/commands/select/select_test.go index 5a34d71e..79c8cbf0 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -1,7 +1,6 @@ package _select import ( - "fmt" "io/ioutil" "log" "testing" @@ -92,8 +91,6 @@ func createRepo() *repository.GitRepo { log.Fatal(err) } - fmt.Println("Creating repo:", dir) - repo, err := repository.InitGitRepo(dir) if err != nil { log.Fatal(err) |