1package commands
2
3import (
4 "github.com/spf13/cobra"
5)
6
7func newUserAdoptCommand() *cobra.Command {
8 env := newEnv()
9
10 cmd := &cobra.Command{
11 Use: "adopt USER-ID",
12 Short: "Adopt an existing identity as your own.",
13 Args: cobra.ExactArgs(1),
14 PreRunE: loadBackend(env),
15 RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
16 return runUserAdopt(env, args)
17 }),
18 }
19
20 return cmd
21}
22
23func runUserAdopt(env *Env, args []string) error {
24 prefix := args[0]
25
26 i, err := env.backend.ResolveIdentityPrefix(prefix)
27 if err != nil {
28 return err
29 }
30
31 err = env.backend.SetUserIdentity(i)
32 if err != nil {
33 return err
34 }
35
36 env.out.Printf("Your identity is now: %s\n", i.DisplayName())
37
38 return nil
39}