aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/user_adopt.go48
-rw-r--r--commands/user_create.go4
2 files changed, 52 insertions, 0 deletions
diff --git a/commands/user_adopt.go b/commands/user_adopt.go
new file mode 100644
index 00000000..5313e366
--- /dev/null
+++ b/commands/user_adopt.go
@@ -0,0 +1,48 @@
+package commands
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/util/interrupt"
+ "github.com/spf13/cobra"
+)
+
+func runUserAdopt(cmd *cobra.Command, args []string) error {
+ backend, err := cache.NewRepoCache(repo)
+ if err != nil {
+ return err
+ }
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ prefix := args[0]
+
+ i, err := backend.ResolveIdentityPrefix(prefix)
+ if err != nil {
+ return err
+ }
+
+ err = backend.SetUserIdentity(i)
+ if err != nil {
+ return err
+ }
+
+ _, _ = fmt.Fprintf(os.Stderr, "Your identity is now: %s\n", i.DisplayName())
+
+ return nil
+}
+
+var userAdoptCmd = &cobra.Command{
+ Use: "adopt <id>",
+ Short: "Adopt an existing identity as your own.",
+ PreRunE: loadRepo,
+ RunE: runUserAdopt,
+ Args: cobra.ExactArgs(1),
+}
+
+func init() {
+ userCmd.AddCommand(userAdoptCmd)
+ userAdoptCmd.Flags().SortFlags = false
+}
diff --git a/commands/user_create.go b/commands/user_create.go
index 2d007600..00ec5b9b 100644
--- a/commands/user_create.go
+++ b/commands/user_create.go
@@ -18,6 +18,10 @@ func runUserCreate(cmd *cobra.Command, args []string) error {
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
+ _, _ = fmt.Fprintf(os.Stderr, "Before creating a new identity, please be aware that "+
+ "you can also use an already existing one using \"git bug user adopt\". As an example, "+
+ "you can do that if your identity has already been created by an importer.\n\n")
+
preName, err := backend.GetUserName()
if err != nil {
return err