git-bug/commands/bridge_auth_rm.go
Johannes Altmanninger bc6ba02bd8
Add command-specific argument completions
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched with Ctrl+S.

Reproduce with

	fish -C 'source misc/fish_completion/git-bug'
	git bug select ^I

(tested with fish version 3.3.1)

Also works with bash, but only for "git-bug" (with the dash)

	bash --rcfile <(echo source misc/bash_completion/git-bug)
	git-bug select ^I

Closes #493
2022-05-01 10:54:13 +02:00

40 lines
758 B
Go

package commands
import (
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge/core/auth"
)
func newBridgeAuthRm() *cobra.Command {
env := newEnv()
cmd := &cobra.Command{
Use: "rm ID",
Short: "Remove a credential.",
PreRunE: loadRepo(env),
RunE: func(cmd *cobra.Command, args []string) error {
return runBridgeAuthRm(env, args)
},
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeBridgeAuth(env),
}
return cmd
}
func runBridgeAuthRm(env *Env, args []string) error {
cred, err := auth.LoadWithPrefix(env.repo, args[0])
if err != nil {
return err
}
err = auth.Remove(env.repo, cred.ID())
if err != nil {
return err
}
env.out.Printf("credential %s removed\n", cred.ID())
return nil
}