aboutsummaryrefslogtreecommitdiffstats
path: root/commands/execenv
diff options
context:
space:
mode:
Diffstat (limited to 'commands/execenv')
-rw-r--r--commands/execenv/env.go18
-rw-r--r--commands/execenv/env_testing.go10
2 files changed, 25 insertions, 3 deletions
diff --git a/commands/execenv/env.go b/commands/execenv/env.go
index 9b71a45a..4be7c247 100644
--- a/commands/execenv/env.go
+++ b/commands/execenv/env.go
@@ -1,6 +1,7 @@
package execenv
import (
+ "encoding/json"
"fmt"
"io"
"os"
@@ -8,7 +9,6 @@ import (
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/interrupt"
@@ -39,6 +39,7 @@ type Out interface {
Printf(format string, a ...interface{})
Print(a ...interface{})
Println(a ...interface{})
+ PrintJSON(v interface{}) error
// String returns what have been written in the output before, as a string.
// This only works in test scenario.
@@ -67,6 +68,15 @@ func (o out) Println(a ...interface{}) {
_, _ = fmt.Fprintln(o, a...)
}
+func (o out) PrintJSON(v interface{}) error {
+ raw, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ return err
+ }
+ o.Println(string(raw))
+ return nil
+}
+
func (o out) String() string {
panic("only work with a test env")
}
@@ -87,11 +97,13 @@ func LoadRepo(env *Env) func(*cobra.Command, []string) error {
return fmt.Errorf("unable to get the current working directory: %q", err)
}
- env.Repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, []repository.ClockLoader{bug.ClockLoader})
+ // Note: we are not loading clocks here because we assume that LoadRepo is only used
+ // when we don't manipulate entities, or as a child call of LoadBackend which will
+ // read all clocks anyway.
+ env.Repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, nil)
if err == repository.ErrNotARepo {
return fmt.Errorf("%s must be run from within a git Repo", RootCommandName)
}
-
if err != nil {
return err
}
diff --git a/commands/execenv/env_testing.go b/commands/execenv/env_testing.go
index 5761b410..34eafc9c 100644
--- a/commands/execenv/env_testing.go
+++ b/commands/execenv/env_testing.go
@@ -2,6 +2,7 @@ package execenv
import (
"bytes"
+ "encoding/json"
"fmt"
"testing"
@@ -27,6 +28,15 @@ func (te *TestOut) Println(a ...interface{}) {
_, _ = fmt.Fprintln(te.Buffer, a...)
}
+func (te *TestOut) PrintJSON(v interface{}) error {
+ raw, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ return err
+ }
+ te.Println(string(raw))
+ return nil
+}
+
func NewTestEnv(t *testing.T) *Env {
t.Helper()