mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
commands: add a "user adopt" command to use an existing identity
This commit is contained in:
parent
7a80d8f849
commit
304a334930
48
commands/user_adopt.go
Normal file
48
commands/user_adopt.go
Normal 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
|
||||
}
|
@ -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
|
||||
|
29
doc/man/git-bug-user-adopt.1
Normal file
29
doc/man/git-bug-user-adopt.1
Normal 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
|
@ -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
|
||||
|
22
doc/md/git-bug_user_adopt.md
Normal file
22
doc/md/git-bug_user_adopt.md
Normal 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.
|
||||
|
@ -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")
|
||||
|
||||
|
@ -33,7 +33,7 @@ case $state in
|
||||
_arguments '2: :(edit)'
|
||||
;;
|
||||
user)
|
||||
_arguments '2: :(create ls)'
|
||||
_arguments '2: :(adopt create ls)'
|
||||
;;
|
||||
*)
|
||||
_arguments '*: :_files'
|
||||
|
Loading…
Reference in New Issue
Block a user