mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
commands: add the "bridge" and "bridge configure" commands
This commit is contained in:
parent
5e8fb7ec50
commit
43bda202fa
38
commands/bridge.go
Normal file
38
commands/bridge.go
Normal 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)
|
||||
}
|
95
commands/bridge_configure.go
Normal file
95
commands/bridge_configure.go
Normal 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)
|
||||
}
|
@ -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)
|
||||
|
29
doc/man/git-bug-bridge-bridge.1
Normal file
29
doc/man/git-bug-bridge-bridge.1
Normal 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
|
29
doc/man/git-bug-bridge-configure.1
Normal file
29
doc/man/git-bug-bridge-configure.1
Normal 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
29
doc/man/git-bug-bridge.1
Normal 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
|
@ -29,4 +29,4 @@ It use the same internal storage so it doesn't pollute your project. As you woul
|
||||
|
||||
.SH SEE ALSO
|
||||
.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
|
||||
|
@ -21,6 +21,7 @@ git-bug [flags]
|
||||
### SEE ALSO
|
||||
|
||||
* [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 comment](git-bug_comment.md) - Display or add comments
|
||||
* [git-bug label](git-bug_label.md) - Display, add or remove labels
|
||||
|
23
doc/md/git-bug_bridge.md
Normal file
23
doc/md/git-bug_bridge.md
Normal 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
|
||||
|
22
doc/md/git-bug_bridge_bridge.md
Normal file
22
doc/md/git-bug_bridge_bridge.md
Normal 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
|
||||
|
22
doc/md/git-bug_bridge_configure.md
Normal file
22
doc/md/git-bug_bridge_configure.md
Normal 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
|
||||
|
@ -277,6 +277,47 @@ _git-bug_add()
|
||||
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()
|
||||
{
|
||||
last_command="git-bug_commands"
|
||||
@ -704,6 +745,7 @@ _git-bug_root_command()
|
||||
|
||||
commands=()
|
||||
commands+=("add")
|
||||
commands+=("bridge")
|
||||
commands+=("commands")
|
||||
commands+=("comment")
|
||||
commands+=("label")
|
||||
|
@ -8,7 +8,7 @@ case $state in
|
||||
level1)
|
||||
case $words[1] in
|
||||
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'
|
||||
@ -17,6 +17,9 @@ case $state in
|
||||
;;
|
||||
level2)
|
||||
case $words[2] in
|
||||
bridge)
|
||||
_arguments '2: :(configure)'
|
||||
;;
|
||||
comment)
|
||||
_arguments '2: :(add)'
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user