aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/bridge_token.go45
-rw-r--r--commands/bridge_token_add.go44
-rw-r--r--commands/bridge_token_rm.go29
3 files changed, 108 insertions, 10 deletions
diff --git a/commands/bridge_token.go b/commands/bridge_token.go
index 6cb6c4b7..52dea9a9 100644
--- a/commands/bridge_token.go
+++ b/commands/bridge_token.go
@@ -2,16 +2,18 @@ package commands
import (
"fmt"
+ "strings"
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/util/colors"
"github.com/MichaelMure/git-bug/util/interrupt"
+ "github.com/MichaelMure/git-bug/util/text"
)
var (
- bridgeTokenAll bool
bridgeTokenLocalOnly bool
bridgeTokenGlobalOnly bool
)
@@ -24,25 +26,49 @@ func runTokenBridge(cmd *cobra.Command, args []string) error {
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
- var tokens []string
- if bridgeTokenLocalOnly || bridgeTokenAll {
+ var tokens []*core.Token
+ if !bridgeTokenGlobalOnly {
localTokens, err := core.ListTokens(backend)
if err != nil {
return err
}
- tokens = localTokens
+
+ for _, id := range localTokens {
+ token, err := core.GetToken(repo, id)
+ if err != nil {
+ return err
+ }
+ tokens = append(tokens, token)
+ }
}
- if bridgeTokenGlobalOnly || bridgeTokenAll {
+ if !bridgeTokenLocalOnly {
globalTokens, err := core.ListGlobalTokens(backend)
if err != nil {
return err
}
- tokens = append(tokens, globalTokens...)
+
+ for _, id := range globalTokens {
+ token, err := core.GetGlobalToken(repo, id)
+ if err != nil {
+ return err
+ }
+ tokens = append(tokens, token)
+ }
}
- for _, c := range tokens {
- fmt.Println(c)
+ for _, token := range tokens {
+ valueFmt := text.LeftPadMaxLine(token.Value, 20, 0)
+ targetFmt := text.LeftPadMaxLine(token.Target, 10, 0)
+ scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0)
+
+ fmt.Printf("%s %s %s %s %s\n",
+ colors.Cyan(token.Id),
+ colors.Magenta(targetFmt),
+ colors.Yellow(token.Global),
+ valueFmt,
+ scopesFmt,
+ )
}
return nil
}
@@ -57,8 +83,7 @@ var bridgeTokenCmd = &cobra.Command{
func init() {
bridgeCmd.AddCommand(bridgeTokenCmd)
- bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenAll, "all", "a", false, "")
- bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", true, "")
+ bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenLocalOnly, "local", "l", false, "")
bridgeTokenCmd.Flags().BoolVarP(&bridgeTokenGlobalOnly, "global", "g", false, "")
bridgeTokenCmd.Flags().SortFlags = false
}
diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go
new file mode 100644
index 00000000..8b3fc5ce
--- /dev/null
+++ b/commands/bridge_token_add.go
@@ -0,0 +1,44 @@
+package commands
+
+import (
+ "github.com/spf13/cobra"
+
+ "github.com/MichaelMure/git-bug/bridge/core"
+)
+
+var (
+ bridgeToken core.Token
+)
+
+func runBridgeTokenAdd(cmd *cobra.Command, args []string) error {
+ if bridgeToken.Global {
+ return core.StoreToken(
+ repo,
+ &bridgeToken,
+ )
+ }
+
+ return core.StoreGlobalToken(
+ repo,
+ &bridgeToken,
+ )
+}
+
+var bridgeTokenAddCmd = &cobra.Command{
+ Use: "add",
+ Short: "Configure and use bridge tokens.",
+ PreRunE: loadRepo,
+ RunE: runBridgeTokenAdd,
+ Args: cobra.NoArgs,
+}
+
+func init() {
+ bridgeTokenCmd.AddCommand(bridgeTokenAddCmd)
+ bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Id, "id", "i", "", "")
+ bridgeTokenAddCmd.Flags().BoolVarP(&bridgeToken.Global, "global", "g", false, "")
+ bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Value, "value", "v", "", "")
+ bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Target, "target", "t", "", "")
+ bridgeTokenAddCmd.Flags().StringArrayVarP(&bridgeToken.Scopes, "scopes", "s", []string{}, "")
+ bridgeTokenAddCmd.Flags().SortFlags = false
+
+}
diff --git a/commands/bridge_token_rm.go b/commands/bridge_token_rm.go
new file mode 100644
index 00000000..7fd79126
--- /dev/null
+++ b/commands/bridge_token_rm.go
@@ -0,0 +1,29 @@
+package commands
+
+import (
+ "github.com/spf13/cobra"
+
+ "github.com/MichaelMure/git-bug/bridge/core"
+)
+
+func runBridgeTokenRm(cmd *cobra.Command, args []string) error {
+ err := core.RemoveToken(repo, args[0])
+ if err == nil {
+ return nil
+ }
+
+ err = core.RemoveGlobalToken(repo, args[0])
+ return err
+}
+
+var bridgeTokenRmCmd = &cobra.Command{
+ Use: "rm",
+ Short: "Configure and use bridge tokens.",
+ PreRunE: loadRepo,
+ RunE: runBridgeTokenRm,
+ Args: cobra.ExactArgs(1),
+}
+
+func init() {
+ bridgeTokenCmd.AddCommand(bridgeTokenRmCmd)
+}