bridge_auth_show.go

 1package commands
 2
 3import (
 4	"fmt"
 5	"time"
 6
 7	"github.com/spf13/cobra"
 8
 9	"github.com/MichaelMure/git-bug/bridge/core/auth"
10)
11
12func runBridgeAuthShow(cmd *cobra.Command, args []string) error {
13	cred, err := auth.LoadWithPrefix(repo, args[0])
14	if err != nil {
15		return err
16	}
17
18	fmt.Printf("Id: %s\n", cred.ID())
19	fmt.Printf("Target: %s\n", cred.Target())
20	fmt.Printf("Kind: %s\n", cred.Kind())
21	fmt.Printf("Creation: %s\n", cred.CreateTime().Format(time.RFC822))
22
23	switch cred := cred.(type) {
24	case *auth.Token:
25		fmt.Printf("Value: %s\n", cred.Value)
26	}
27
28	return nil
29}
30
31var bridgeAuthShowCmd = &cobra.Command{
32	Use:     "show",
33	Short:   "Display an authentication credential.",
34	PreRunE: loadRepo,
35	RunE:    runBridgeAuthShow,
36	Args:    cobra.ExactArgs(1),
37}
38
39func init() {
40	bridgeAuthCmd.AddCommand(bridgeAuthShowCmd)
41}