2019-02-24 16:45:24 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-02-05 00:05:34 +03:00
|
|
|
"github.com/spf13/cobra"
|
2019-02-24 16:45:24 +03:00
|
|
|
)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func newUserAdoptCommand() *cobra.Command {
|
|
|
|
env := newEnv()
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2020-06-28 20:09:32 +03:00
|
|
|
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 {
|
2019-02-24 16:45:24 +03:00
|
|
|
prefix := args[0]
|
|
|
|
|
2020-06-28 20:09:32 +03:00
|
|
|
i, err := env.backend.ResolveIdentityPrefix(prefix)
|
2019-02-24 16:45:24 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:09:32 +03:00
|
|
|
err = env.backend.SetUserIdentity(i)
|
2019-02-24 16:45:24 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Printf("Your identity is now: %s\n", i.DisplayName())
|
2019-02-24 16:45:24 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|