diff options
author | Michael Muré <batolettre@gmail.com> | 2020-06-28 18:26:29 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-06-28 18:26:29 +0200 |
commit | 26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch) | |
tree | f1fe939311c75bd615071e96f3d37822cccd77a7 /commands/termui.go | |
parent | c0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff) | |
download | git-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz |
commands: refactor to avoid globals
Diffstat (limited to 'commands/termui.go')
-rw-r--r-- | commands/termui.go | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/commands/termui.go b/commands/termui.go index 2cdc3507..174d60ec 100644 --- a/commands/termui.go +++ b/commands/termui.go @@ -1,14 +1,31 @@ package commands import ( + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/termui" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) -func runTermUI(cmd *cobra.Command, args []string) error { - backend, err := cache.NewRepoCache(repo) +func newTermUICommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "termui", + Aliases: []string{"tui"}, + Short: "Launch the terminal UI.", + PreRunE: loadRepoEnsureUser(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runTermUI(env) + }, + } + + return cmd +} + +func runTermUI(env *Env) error { + backend, err := cache.NewRepoCache(env.repo) if err != nil { return err } @@ -17,15 +34,3 @@ func runTermUI(cmd *cobra.Command, args []string) error { return termui.Run(backend) } - -var termUICmd = &cobra.Command{ - Use: "termui", - Aliases: []string{"tui"}, - Short: "Launch the terminal UI.", - PreRunE: loadRepoEnsureUser, - RunE: runTermUI, -} - -func init() { - RootCmd.AddCommand(termUICmd) -} |