git-bug/commands/user_adopt.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

41 lines
765 B
Go

package commands
import (
"github.com/spf13/cobra"
)
func newUserAdoptCommand() *cobra.Command {
env := newEnv()
cmd := &cobra.Command{
Use: "adopt USER-ID",
Short: "Adopt an existing identity as your own.",
Args: cobra.ExactArgs(1),
PreRunE: loadBackend(env),
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runUserAdopt(env, args)
}),
ValidArgsFunction: completeUser(env),
}
return cmd
}
func runUserAdopt(env *Env, args []string) error {
prefix := args[0]
i, err := env.backend.ResolveIdentityPrefix(prefix)
if err != nil {
return err
}
err = env.backend.SetUserIdentity(i)
if err != nil {
return err
}
env.out.Printf("Your identity is now: %s\n", i.DisplayName())
return nil
}