diff options
author | Michael Muré <batolettre@gmail.com> | 2020-06-28 19:09:32 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-06-28 19:09:32 +0200 |
commit | 536c290dfbe6e0741c56f33659563c528c9f09b1 (patch) | |
tree | 79ea46f76ac6f69c2e6cbf3323be7c620c39a510 /commands/root.go | |
parent | 26bd1dd11010b4d86cebe2510ad7085a6b316334 (diff) | |
download | git-bug-536c290dfbe6e0741c56f33659563c528c9f09b1.tar.gz |
commands: open and close the backend in a single place, simplify commands
Diffstat (limited to 'commands/root.go')
-rw-r--r-- | commands/root.go | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/commands/root.go b/commands/root.go index 42859d19..a67fec1a 100644 --- a/commands/root.go +++ b/commands/root.go @@ -6,10 +6,6 @@ import ( "os" "github.com/spf13/cobra" - - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/repository" ) const rootCommandName = "git-bug" @@ -92,43 +88,3 @@ func Execute() { os.Exit(1) } } - -// loadRepo is a pre-run function that load the repository for use in a command -func loadRepo(env *Env) func(*cobra.Command, []string) error { - return func(cmd *cobra.Command, args []string) error { - cwd, err := os.Getwd() - if err != nil { - return fmt.Errorf("unable to get the current working directory: %q", err) - } - - env.repo, err = repository.NewGitRepo(cwd, []repository.ClockLoader{bug.ClockLoader}) - if err == repository.ErrNotARepo { - return fmt.Errorf("%s must be run from within a git repo", rootCommandName) - } - - if err != nil { - return err - } - - 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(env *Env) func(*cobra.Command, []string) error { - return func(cmd *cobra.Command, args []string) error { - err := loadRepo(env)(cmd, args) - if err != nil { - return err - } - - _, err = identity.GetUserIdentity(env.repo) - if err != nil { - return err - } - - return nil - } -} |