aboutsummaryrefslogtreecommitdiffstats
path: root/commands/title.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/title.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/title.go')
-rw-r--r--commands/title.go39
1 files changed, 21 insertions, 18 deletions
diff --git a/commands/title.go b/commands/title.go
index 66a9de7a..c1a0e7fb 100644
--- a/commands/title.go
+++ b/commands/title.go
@@ -1,16 +1,32 @@
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 runTitle(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newTitleCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "title [<id>]",
+ Short: "Display or change a title of a bug.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runTitle(env, args)
+ },
+ }
+
+ cmd.AddCommand(newTitleEditCommand())
+
+ return cmd
+}
+
+func runTitle(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -24,20 +40,7 @@ func runTitle(cmd *cobra.Command, args []string) error {
snap := b.Snapshot()
- fmt.Println(snap.Title)
+ env.out.Println(snap.Title)
return nil
}
-
-var titleCmd = &cobra.Command{
- Use: "title [<id>]",
- Short: "Display or change a title of a bug.",
- PreRunE: loadRepo,
- RunE: runTitle,
-}
-
-func init() {
- RootCmd.AddCommand(titleCmd)
-
- titleCmd.Flags().SortFlags = false
-}