aboutsummaryrefslogtreecommitdiffstats
path: root/commands/root.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-23 13:01:46 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:28 +0100
commitb8caddddc7aaf34b2da61c590fd1d9a0fae024fb (patch)
tree05871cd66dd4ae9a02f4221b6a8c235931e93074 /commands/root.go
parent719303226096c905e602cb620dfdfbcf8fe106ad (diff)
downloadgit-bug-b8caddddc7aaf34b2da61c590fd1d9a0fae024fb.tar.gz
identity: some UX cleanup
Diffstat (limited to 'commands/root.go')
-rw-r--r--commands/root.go23
1 files changed, 23 insertions, 0 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
+}