commands: add the "bridge" and "bridge configure" commands

This commit is contained in:
Michael Muré 2018-09-24 15:25:57 +02:00
parent 5e8fb7ec50
commit 43bda202fa
No known key found for this signature in database
GPG Key ID: A4457C029293126F
13 changed files with 335 additions and 5 deletions

38
commands/bridge.go Normal file
View File

@ -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)
}

View File

@ -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)
}

View File

@ -1,7 +1,6 @@
package _select package _select
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"testing" "testing"
@ -92,8 +91,6 @@ func createRepo() *repository.GitRepo {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println("Creating repo:", dir)
repo, err := repository.InitGitRepo(dir) repo, err := repository.InitGitRepo(dir)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -0,0 +1,29 @@
.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" ""
.nh
.ad l
.SH NAME
.PP
git\-bug\-bridge\-bridge \- Configure and use bridges to other bug trackers
.SH SYNOPSIS
.PP
\fBgit\-bug bridge bridge [flags]\fP
.SH DESCRIPTION
.PP
Configure and use bridges to other bug trackers
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for bridge
.SH SEE ALSO
.PP
\fBgit\-bug\-bridge(1)\fP

View File

@ -0,0 +1,29 @@
.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" ""
.nh
.ad l
.SH NAME
.PP
git\-bug\-bridge\-configure \- Configure a new bridge
.SH SYNOPSIS
.PP
\fBgit\-bug bridge configure [flags]\fP
.SH DESCRIPTION
.PP
Configure a new bridge
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for configure
.SH SEE ALSO
.PP
\fBgit\-bug\-bridge(1)\fP

29
doc/man/git-bug-bridge.1 Normal file
View File

@ -0,0 +1,29 @@
.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" ""
.nh
.ad l
.SH NAME
.PP
git\-bug\-bridge \- Configure and use bridges to other bug trackers
.SH SYNOPSIS
.PP
\fBgit\-bug bridge [flags]\fP
.SH DESCRIPTION
.PP
Configure and use bridges to other bug trackers
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for bridge
.SH SEE ALSO
.PP
\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP

View File

@ -29,4 +29,4 @@ It use the same internal storage so it doesn't pollute your project. As you woul
.SH SEE ALSO .SH SEE ALSO
.PP .PP
\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-ls\-label(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-select(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-status(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-title(1)\fP, \fBgit\-bug\-webui(1)\fP \fBgit\-bug\-add(1)\fP, \fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-ls\-label(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-select(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-status(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-title(1)\fP, \fBgit\-bug\-webui(1)\fP

View File

@ -21,6 +21,7 @@ git-bug [flags]
### SEE ALSO ### SEE ALSO
* [git-bug add](git-bug_add.md) - Create a new bug * [git-bug add](git-bug_add.md) - Create a new bug
* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers
* [git-bug commands](git-bug_commands.md) - Display available commands * [git-bug commands](git-bug_commands.md) - Display available commands
* [git-bug comment](git-bug_comment.md) - Display or add comments * [git-bug comment](git-bug_comment.md) - Display or add comments
* [git-bug label](git-bug_label.md) - Display, add or remove labels * [git-bug label](git-bug_label.md) - Display, add or remove labels

23
doc/md/git-bug_bridge.md Normal file
View File

@ -0,0 +1,23 @@
## git-bug bridge
Configure and use bridges to other bug trackers
### Synopsis
Configure and use bridges to other bug trackers
```
git-bug bridge [flags]
```
### Options
```
-h, --help help for bridge
```
### SEE ALSO
* [git-bug](git-bug.md) - A bug tracker embedded in Git
* [git-bug bridge configure](git-bug_bridge_configure.md) - Configure a new bridge

View File

@ -0,0 +1,22 @@
## git-bug bridge bridge
Configure and use bridges to other bug trackers
### Synopsis
Configure and use bridges to other bug trackers
```
git-bug bridge bridge [flags]
```
### Options
```
-h, --help help for bridge
```
### SEE ALSO
* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers

View File

@ -0,0 +1,22 @@
## git-bug bridge configure
Configure a new bridge
### Synopsis
Configure a new bridge
```
git-bug bridge configure [flags]
```
### Options
```
-h, --help help for configure
```
### SEE ALSO
* [git-bug bridge](git-bug_bridge.md) - Configure and use bridges to other bug trackers

View File

@ -277,6 +277,47 @@ _git-bug_add()
noun_aliases=() noun_aliases=()
} }
_git-bug_bridge_configure()
{
last_command="git-bug_bridge_configure"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_git-bug_bridge()
{
last_command="git-bug_bridge"
command_aliases=()
commands=()
commands+=("configure")
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_git-bug_commands() _git-bug_commands()
{ {
last_command="git-bug_commands" last_command="git-bug_commands"
@ -704,6 +745,7 @@ _git-bug_root_command()
commands=() commands=()
commands+=("add") commands+=("add")
commands+=("bridge")
commands+=("commands") commands+=("commands")
commands+=("comment") commands+=("comment")
commands+=("label") commands+=("label")

View File

@ -8,7 +8,7 @@ case $state in
level1) level1)
case $words[1] in case $words[1] in
git-bug) git-bug)
_arguments '1: :(add commands comment label ls ls-label pull push select show status termui title webui)' _arguments '1: :(add bridge commands comment label ls ls-label pull push select show status termui title webui)'
;; ;;
*) *)
_arguments '*: :_files' _arguments '*: :_files'
@ -17,6 +17,9 @@ case $state in
;; ;;
level2) level2)
case $words[2] in case $words[2] in
bridge)
_arguments '2: :(configure)'
;;
comment) comment)
_arguments '2: :(add)' _arguments '2: :(add)'
;; ;;