diff --git a/commands/user_adopt.go b/commands/user_adopt.go new file mode 100644 index 0000000000000000000000000000000000000000..5313e366696bfc716dae4d25747120cfd32645d8 --- /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 ", + 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 2d00760035d611cd56d8973dcf8db2c40c78e12d..00ec5b9b409cfdb3272e126ef77b86091b44e26b 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 diff --git a/doc/man/git-bug-user-adopt.1 b/doc/man/git-bug-user-adopt.1 new file mode 100644 index 0000000000000000000000000000000000000000..f61bc5d4bdb2b6eff871dbc865f2971f2c2a5c82 --- /dev/null +++ b/doc/man/git-bug-user-adopt.1 @@ -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 [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 diff --git a/doc/man/git-bug-user.1 b/doc/man/git-bug-user.1 index acb9259f5a01e544199fcbe3d4f228c7768110f0..65988c9b7a501733973b5d35d512316f1ae7f36d 100644 --- a/doc/man/git-bug-user.1 +++ b/doc/man/git-bug-user.1 @@ -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 diff --git a/doc/md/git-bug_user_adopt.md b/doc/md/git-bug_user_adopt.md new file mode 100644 index 0000000000000000000000000000000000000000..f89cdf687b00c1d6f1eebe3aed57ec959c7e1ad2 --- /dev/null +++ b/doc/md/git-bug_user_adopt.md @@ -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 [flags] +``` + +### Options + +``` + -h, --help help for adopt +``` + +### SEE ALSO + +* [git-bug user](git-bug_user.md) - Display or change the user identity. + diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 237a0df01b85cbd47c014efb80c63d5616869832..c83d33ae839830d13fa3c6bd6c18974eb20de9d4 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -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") diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 6fc3cf8e2eca7840001dc371c6b5e3eb27595bc9..232cd3c167471f43f87c8f2db53c34ed380d7ec8 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -33,7 +33,7 @@ case $state in _arguments '2: :(edit)' ;; user) - _arguments '2: :(create ls)' + _arguments '2: :(adopt create ls)' ;; *) _arguments '*: :_files'