1package commands
2
3import (
4 "fmt"
5 "os"
6
7 "github.com/spf13/cobra"
8
9 "github.com/MichaelMure/git-bug/cache"
10 "github.com/MichaelMure/git-bug/util/interrupt"
11)
12
13func runUserAdopt(cmd *cobra.Command, args []string) error {
14 backend, err := cache.NewRepoCache(repo)
15 if err != nil {
16 return err
17 }
18 defer backend.Close()
19 interrupt.RegisterCleaner(backend.Close)
20
21 prefix := args[0]
22
23 i, err := backend.ResolveIdentityPrefix(prefix)
24 if err != nil {
25 return err
26 }
27
28 err = backend.SetUserIdentity(i)
29 if err != nil {
30 return err
31 }
32
33 _, _ = fmt.Fprintf(os.Stderr, "Your identity is now: %s\n", i.DisplayName())
34
35 return nil
36}
37
38var userAdoptCmd = &cobra.Command{
39 Use: "adopt <user-id>",
40 Short: "Adopt an existing identity as your own.",
41 PreRunE: loadRepo,
42 RunE: runUserAdopt,
43 Args: cobra.ExactArgs(1),
44}
45
46func init() {
47 userCmd.AddCommand(userAdoptCmd)
48 userAdoptCmd.Flags().SortFlags = false
49}