diff options
Diffstat (limited to 'commands/status.go')
-rw-r--r-- | commands/status.go | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/commands/status.go b/commands/status.go index 4675195d..57771bca 100644 --- a/commands/status.go +++ b/commands/status.go @@ -1,41 +1,39 @@ 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) - if err != nil { - return err +func newStatusCommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "status [<id>]", + Short: "Display or change a bug status.", + PreRunE: loadBackend(env), + PostRunE: closeBackend(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runStatus(env, args) + }, } - defer backend.Close() - interrupt.RegisterCleaner(backend.Close) - b, args, err := _select.ResolveBug(backend, args) + cmd.AddCommand(newStatusCloseCommand()) + cmd.AddCommand(newStatusOpenCommand()) + + return cmd +} + +func runStatus(env *Env, args []string) error { + b, args, err := _select.ResolveBug(env.backend, args) if err != nil { return err } 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) -} |