aboutsummaryrefslogtreecommitdiffstats
path: root/commands/status.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
commit26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch)
treef1fe939311c75bd615071e96f3d37822cccd77a7 /commands/status.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/status.go')
-rw-r--r--commands/status.go38
1 files changed, 22 insertions, 16 deletions
diff --git a/commands/status.go b/commands/status.go
index 4675195d..aaf9e636 100644
--- a/commands/status.go
+++ b/commands/status.go
@@ -1,16 +1,33 @@
package commands
import (
- "fmt"
+ "github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/spf13/cobra"
)
-func runStatus(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newStatusCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "status [<id>]",
+ Short: "Display or change a bug status.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runStatus(env, args)
+ },
+ }
+
+ cmd.AddCommand(newStatusCloseCommand())
+ cmd.AddCommand(newStatusOpenCommand())
+
+ return cmd
+}
+
+func runStatus(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -24,18 +41,7 @@ func runStatus(cmd *cobra.Command, args []string) error {
snap := b.Snapshot()
- fmt.Println(snap.Status)
+ env.out.Println(snap.Status)
return nil
}
-
-var statusCmd = &cobra.Command{
- Use: "status [<id>]",
- Short: "Display or change a bug status.",
- PreRunE: loadRepo,
- RunE: runStatus,
-}
-
-func init() {
- RootCmd.AddCommand(statusCmd)
-}