commands: add a "user adopt" command to use an existing identity

This commit is contained in:
Michael Muré 2019-02-24 14:45:24 +01:00
parent 7a80d8f849
commit 304a334930
No known key found for this signature in database
GPG Key ID: A4457C029293126F
7 changed files with 126 additions and 2 deletions

48
commands/user_adopt.go Normal file
View File

@ -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
}

View File

@ -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

View File

@ -0,0 +1,29 @@
.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" ""
.nh
.ad l
.SH NAME
.PP
git\-bug\-user\-adopt \- Adopt an existing identity as your own.
.SH SYNOPSIS
.PP
\fBgit\-bug user adopt <id> [flags]\fP
.SH DESCRIPTION
.PP
Adopt an existing identity as your own.
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for adopt
.SH SEE ALSO
.PP
\fBgit\-bug\-user(1)\fP

View File

@ -26,4 +26,4 @@ Display or change the user identity
.SH SEE ALSO
.PP
\fBgit\-bug(1)\fP, \fBgit\-bug\-user\-create(1)\fP, \fBgit\-bug\-user\-ls(1)\fP
\fBgit\-bug(1)\fP, \fBgit\-bug\-user\-adopt(1)\fP, \fBgit\-bug\-user\-create(1)\fP, \fBgit\-bug\-user\-ls(1)\fP

View File

@ -0,0 +1,22 @@
## git-bug user adopt
Adopt an existing identity as your own.
### Synopsis
Adopt an existing identity as your own.
```
git-bug user adopt <id> [flags]
```
### Options
```
-h, --help help for adopt
```
### SEE ALSO
* [git-bug user](git-bug_user.md) - Display or change the user identity.

View File

@ -799,6 +799,26 @@ _git-bug_title()
noun_aliases=()
}
_git-bug_user_adopt()
{
last_command="git-bug_user_adopt"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_git-bug_user_create()
{
last_command="git-bug_user_create"
@ -849,6 +869,7 @@ _git-bug_user()
command_aliases=()
commands=()
commands+=("adopt")
commands+=("create")
commands+=("ls")

View File

@ -33,7 +33,7 @@ case $state in
_arguments '2: :(edit)'
;;
user)
_arguments '2: :(create ls)'
_arguments '2: :(adopt create ls)'
;;
*)
_arguments '*: :_files'