aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/root.go23
-rw-r--r--commands/termui.go2
-rw-r--r--commands/user_create.go3
3 files changed, 26 insertions, 2 deletions
diff --git a/commands/root.go b/commands/root.go
index 797ae949..04bd6a83 100644
--- a/commands/root.go
+++ b/commands/root.go
@@ -6,6 +6,7 @@ import (
"os"
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
"github.com/spf13/cobra"
)
@@ -53,6 +54,7 @@ func Execute() {
}
}
+// loadRepo is a pre-run function that load the repository for use in a command
func loadRepo(cmd *cobra.Command, args []string) error {
cwd, err := os.Getwd()
if err != nil {
@@ -70,3 +72,24 @@ func loadRepo(cmd *cobra.Command, args []string) error {
return nil
}
+
+// loadRepoEnsureUser is the same as loadRepo, but also ensure that the user has configured
+// an identity. Use this pre-run function when an error after using the configured user won't
+// do.
+func loadRepoEnsureUser(cmd *cobra.Command, args []string) error {
+ err := loadRepo(cmd, args)
+ if err != nil {
+ return err
+ }
+
+ set, err := identity.IsUserIdentitySet(repo)
+ if err != nil {
+ return err
+ }
+
+ if !set {
+ return identity.ErrNoIdentitySet
+ }
+
+ return nil
+}
diff --git a/commands/termui.go b/commands/termui.go
index 4a029d6c..abfd165f 100644
--- a/commands/termui.go
+++ b/commands/termui.go
@@ -21,7 +21,7 @@ func runTermUI(cmd *cobra.Command, args []string) error {
var termUICmd = &cobra.Command{
Use: "termui",
Short: "Launch the terminal UI",
- PreRunE: loadRepo,
+ PreRunE: loadRepoEnsureUser,
RunE: runTermUI,
}
diff --git a/commands/user_create.go b/commands/user_create.go
index 50acac3e..2d007600 100644
--- a/commands/user_create.go
+++ b/commands/user_create.go
@@ -2,6 +2,7 @@ package commands
import (
"fmt"
+ "os"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/input"
@@ -57,7 +58,7 @@ func runUserCreate(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Println()
+ _, _ = fmt.Fprintln(os.Stderr)
fmt.Println(id.Id())
return nil