aboutsummaryrefslogtreecommitdiffstats
path: root/commands/user_create.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-17 16:12:06 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:25 +0100
commit864eae0d6bd0732260c0c56583bb77f9b25b60f6 (patch)
treeb1a0384f2fdb0af0c8aaf0f1b0fbc1c445c418f3 /commands/user_create.go
parentda558b05ef79f4c80df10c6969a9ae5f4f764f96 (diff)
downloadgit-bug-864eae0d6bd0732260c0c56583bb77f9b25b60f6.tar.gz
identity: work on higher level now, cache, first two identity commands
Diffstat (limited to 'commands/user_create.go')
-rw-r--r--commands/user_create.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/commands/user_create.go b/commands/user_create.go
new file mode 100644
index 00000000..50acac3e
--- /dev/null
+++ b/commands/user_create.go
@@ -0,0 +1,76 @@
+package commands
+
+import (
+ "fmt"
+
+ "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/input"
+ "github.com/MichaelMure/git-bug/util/interrupt"
+ "github.com/spf13/cobra"
+)
+
+func runUserCreate(cmd *cobra.Command, args []string) error {
+ backend, err := cache.NewRepoCache(repo)
+ if err != nil {
+ return err
+ }
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ preName, err := backend.GetUserName()
+ if err != nil {
+ return err
+ }
+
+ name, err := input.PromptValueRequired("Name", preName)
+ if err != nil {
+ return err
+ }
+
+ preEmail, err := backend.GetUserEmail()
+ if err != nil {
+ return err
+ }
+
+ email, err := input.PromptValueRequired("Email", preEmail)
+ if err != nil {
+ return err
+ }
+
+ login, err := input.PromptValue("Avatar URL", "")
+ if err != nil {
+ return err
+ }
+
+ id, err := backend.NewIdentityRaw(name, email, "", login, nil)
+ if err != nil {
+ return err
+ }
+
+ err = id.CommitAsNeeded()
+ if err != nil {
+ return err
+ }
+
+ err = backend.SetUserIdentity(id)
+ if err != nil {
+ return err
+ }
+
+ fmt.Println()
+ fmt.Println(id.Id())
+
+ return nil
+}
+
+var userCreateCmd = &cobra.Command{
+ Use: "create",
+ Short: "Create a new identity",
+ PreRunE: loadRepo,
+ RunE: runUserCreate,
+}
+
+func init() {
+ userCmd.AddCommand(userCreateCmd)
+ userCreateCmd.Flags().SortFlags = false
+}