cli: add bridge token show

Michael Muré created

Change summary

bridge/core/token.go                |  2 
commands/bridge_token_rm.go         |  4 +-
commands/bridge_token_show.go       | 36 ++++++++++++++++++++++++++++++
doc/man/git-bug-bridge-token-rm.1   |  6 ++--
doc/man/git-bug-bridge-token-show.1 | 29 ++++++++++++++++++++++++
doc/man/git-bug-bridge-token.1      |  2 
doc/md/git-bug_bridge_token.md      |  3 +
doc/md/git-bug_bridge_token_rm.md   |  6 ++--
doc/md/git-bug_bridge_token_show.md | 22 ++++++++++++++++++
misc/bash_completion/git-bug        | 21 ++++++++++++++++++
misc/powershell_completion/git-bug  |  6 ++++
misc/zsh_completion/git-bug         | 10 +++++++
12 files changed, 134 insertions(+), 13 deletions(-)

Detailed changes

bridge/core/token.go 🔗

@@ -55,7 +55,7 @@ func (t *Token) Validate() error {
 	if t.Target == "" {
 		return fmt.Errorf("missing target")
 	}
-	if t.CreateTime.IsZero() {
+	if t.CreateTime.IsZero() || t.CreateTime.Equal(time.Time{}) {
 		return fmt.Errorf("missing creation time")
 	}
 	if !TargetExist(t.Target) {

commands/bridge_token_rm.go 🔗

@@ -24,8 +24,8 @@ func runBridgeTokenRm(cmd *cobra.Command, args []string) error {
 }
 
 var bridgeTokenRmCmd = &cobra.Command{
-	Use:     "rm",
-	Short:   "Remove token by Id.",
+	Use:     "rm <id>",
+	Short:   "Remove a token.",
 	PreRunE: loadRepo,
 	RunE:    runBridgeTokenRm,
 	Args:    cobra.ExactArgs(1),

commands/bridge_token_show.go 🔗

@@ -0,0 +1,36 @@
+package commands
+
+import (
+	"fmt"
+	"time"
+
+	"github.com/spf13/cobra"
+
+	"github.com/MichaelMure/git-bug/bridge/core"
+)
+
+func runBridgeTokenShow(cmd *cobra.Command, args []string) error {
+	token, err := core.LoadTokenPrefix(repo, args[0])
+	if err != nil {
+		return err
+	}
+
+	fmt.Printf("Id: %s\n", token.ID())
+	fmt.Printf("Value: %s\n", token.Value)
+	fmt.Printf("Target: %s\n", token.Target)
+	fmt.Printf("Creation: %s\n", token.CreateTime.Format(time.RFC822))
+
+	return nil
+}
+
+var bridgeTokenShowCmd = &cobra.Command{
+	Use:     "show",
+	Short:   "Display a token.",
+	PreRunE: loadRepo,
+	RunE:    runBridgeTokenShow,
+	Args:    cobra.ExactArgs(1),
+}
+
+func init() {
+	bridgeTokenCmd.AddCommand(bridgeTokenShowCmd)
+}

doc/man/git-bug-bridge-token-rm.1 🔗

@@ -5,17 +5,17 @@
 
 .SH NAME
 .PP
-git\-bug\-bridge\-token\-rm \- Remove token by Id.
+git\-bug\-bridge\-token\-rm \- Remove a token.
 
 
 .SH SYNOPSIS
 .PP
-\fBgit\-bug bridge token rm [flags]\fP
+\fBgit\-bug bridge token rm <id> [flags]\fP
 
 
 .SH DESCRIPTION
 .PP
-Remove token by Id.
+Remove a token.
 
 
 .SH OPTIONS

doc/man/git-bug-bridge-token-show.1 🔗

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

doc/man/git-bug-bridge-token.1 🔗

@@ -26,4 +26,4 @@ List all known tokens.
 
 .SH SEE ALSO
 .PP
-\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP
+\fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-bridge\-token\-add(1)\fP, \fBgit\-bug\-bridge\-token\-rm(1)\fP, \fBgit\-bug\-bridge\-token\-show(1)\fP

doc/md/git-bug_bridge_token.md 🔗

@@ -20,5 +20,6 @@ git-bug bridge token [flags]
 
 * [git-bug bridge](git-bug_bridge.md)	 - Configure and use bridges to other bug trackers.
 * [git-bug bridge token add](git-bug_bridge_token_add.md)	 - Store a new token
-* [git-bug bridge token rm](git-bug_bridge_token_rm.md)	 - Remove token by Id.
+* [git-bug bridge token rm](git-bug_bridge_token_rm.md)	 - Remove a token.
+* [git-bug bridge token show](git-bug_bridge_token_show.md)	 - Display a token.
 

doc/md/git-bug_bridge_token_rm.md 🔗

@@ -1,13 +1,13 @@
 ## git-bug bridge token rm
 
-Remove token by Id.
+Remove a token.
 
 ### Synopsis
 
-Remove token by Id.
+Remove a token.
 
 ```
-git-bug bridge token rm [flags]
+git-bug bridge token rm <id> [flags]
 ```
 
 ### Options

doc/md/git-bug_bridge_token_show.md 🔗

@@ -0,0 +1,22 @@
+## git-bug bridge token show
+
+Display a token.
+
+### Synopsis
+
+Display a token.
+
+```
+git-bug bridge token show [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for show
+```
+
+### SEE ALSO
+
+* [git-bug bridge token](git-bug_bridge_token.md)	 - List all known tokens.
+

misc/bash_completion/git-bug 🔗

@@ -444,6 +444,26 @@ _git-bug_bridge_token_rm()
     noun_aliases=()
 }
 
+_git-bug_bridge_token_show()
+{
+    last_command="git-bug_bridge_token_show"
+
+    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_token()
 {
     last_command="git-bug_bridge_token"
@@ -453,6 +473,7 @@ _git-bug_bridge_token()
     commands=()
     commands+=("add")
     commands+=("rm")
+    commands+=("show")
 
     flags=()
     two_word_flags=()

misc/powershell_completion/git-bug 🔗

@@ -86,7 +86,8 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
         }
         'git-bug;bridge;token' {
             [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Store a new token')
-            [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove token by Id.')
+            [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a token.')
+            [CompletionResult]::new('show', 'show', [CompletionResultType]::ParameterValue, 'Display a token.')
             break
         }
         'git-bug;bridge;token;add' {
@@ -97,6 +98,9 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
         'git-bug;bridge;token;rm' {
             break
         }
+        'git-bug;bridge;token;show' {
+            break
+        }
         'git-bug;commands' {
             [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment')
             [CompletionResult]::new('--pretty', 'pretty', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment')

misc/zsh_completion/git-bug 🔗

@@ -180,7 +180,8 @@ function _git-bug_bridge_token {
   cmnds)
     commands=(
       "add:Store a new token"
-      "rm:Remove token by Id."
+      "rm:Remove a token."
+      "show:Display a token."
     )
     _describe "command" commands
     ;;
@@ -193,6 +194,9 @@ function _git-bug_bridge_token {
   rm)
     _git-bug_bridge_token_rm
     ;;
+  show)
+    _git-bug_bridge_token_show
+    ;;
   esac
 }
 
@@ -205,6 +209,10 @@ function _git-bug_bridge_token_rm {
   _arguments
 }
 
+function _git-bug_bridge_token_show {
+  _arguments
+}
+
 function _git-bug_commands {
   _arguments \
     '(-p --pretty)'{-p,--pretty}'[Output the command description as well as Markdown compatible comment]'