git-bug/commands/user_adopt.go

41 lines
743 B
Go
Raw Normal View History

package commands
import (
2020-02-05 00:05:34 +03:00
"github.com/spf13/cobra"
)
2020-06-28 19:26:29 +03:00
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),
PostRunE: closeBackend(env),
2020-06-28 19:26:29 +03:00
RunE: func(cmd *cobra.Command, args []string) error {
return runUserAdopt(env, args)
},
}
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
}
2020-06-28 19:26:29 +03:00
env.out.Printf("Your identity is now: %s\n", i.DisplayName())
return nil
}