1package commands
2
3import (
4 "github.com/spf13/cobra"
5
6 "github.com/MichaelMure/git-bug/bridge/core/auth"
7)
8
9func newBridgeAuthRm() *cobra.Command {
10 env := newEnv()
11
12 cmd := &cobra.Command{
13 Use: "rm ID",
14 Short: "Remove a credential.",
15 PreRunE: loadRepo(env),
16 RunE: func(cmd *cobra.Command, args []string) error {
17 return runBridgeAuthRm(env, args)
18 },
19 Args: cobra.ExactArgs(1),
20 ValidArgsFunction: completeBridgeAuth(env),
21 }
22
23 return cmd
24}
25
26func runBridgeAuthRm(env *Env, args []string) error {
27 cred, err := auth.LoadWithPrefix(env.repo, args[0])
28 if err != nil {
29 return err
30 }
31
32 err = auth.Remove(env.repo, cred.ID())
33 if err != nil {
34 return err
35 }
36
37 env.out.Printf("credential %s removed\n", cred.ID())
38 return nil
39}