Skip to content

Commit

Permalink
Merge pull request #962 from MichaelMure/select-completion
Browse files Browse the repository at this point in the history
commands: generic "select" code, move bug completion in bugcmd
  • Loading branch information
MichaelMure committed Dec 27, 2022
2 parents b11f60f + e920987 commit d11ea5c
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 302 deletions.
6 changes: 2 additions & 4 deletions commands/bug/bug_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
text "github.com/MichaelMure/go-term-text"
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
"github.com/MichaelMure/git-bug/util/colors"
)
Expand All @@ -20,7 +18,7 @@ func newBugCommentCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugComment(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

cmd.AddCommand(newBugCommentNewCommand())
Expand All @@ -30,7 +28,7 @@ func newBugCommentCommand() *cobra.Command {
}

func runBugComment(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_comment_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/spf13/cobra"

buginput "github.com/MichaelMure/git-bug/commands/bug/input"
"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
"github.com/MichaelMure/git-bug/util/text"
)
Expand All @@ -27,7 +25,7 @@ func newBugCommentNewCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugCommentNew(env, options, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

flags := cmd.Flags()
Expand All @@ -44,7 +42,7 @@ func newBugCommentNewCommand() *cobra.Command {
}

func runBugCommentNew(env *execenv.Env, opts bugCommentNewOptions, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions commands/bug/bug_deselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/execenv"
_select "github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/entities/bug"
)

func newBugDeselectCommand() *cobra.Command {
Expand All @@ -28,7 +29,7 @@ git bug deselect
}

func runBugDeselect(env *execenv.Env) error {
err := _select.Clear(env.Backend)
err := _select.Clear(env.Backend, bug.Namespace)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -18,7 +16,7 @@ func newBugLabelCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugLabel(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

cmd.AddCommand(newBugLabelNewCommand())
Expand All @@ -28,7 +26,7 @@ func newBugLabelCommand() *cobra.Command {
}

func runBugLabel(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_label_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
"github.com/MichaelMure/git-bug/util/text"
)
Expand All @@ -19,14 +17,14 @@ func newBugLabelNewCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugLabelNew(env, args)
}),
ValidArgsFunction: completion.BugAndLabels(env, true),
ValidArgsFunction: BugAndLabelsCompletion(env, true),
}

return cmd
}

func runBugLabelNew(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_label_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
"github.com/MichaelMure/git-bug/util/text"
)
Expand All @@ -19,14 +17,14 @@ func newBugLabelRmCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugLabelRm(env, args)
}),
ValidArgsFunction: completion.BugAndLabels(env, false),
ValidArgsFunction: BugAndLabelsCompletion(env, false),
}

return cmd
}

func runBugLabelRm(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions commands/bug/bug_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -20,7 +19,7 @@ func newBugRmCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugRm(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

flags := cmd.Flags()
Expand Down
13 changes: 9 additions & 4 deletions commands/bug/bug_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import (

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/commands/execenv"
_select "github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/entities/bug"
)

func ResolveSelected(repo *cache.RepoCache, args []string) (*cache.BugCache, []string, error) {
return _select.Resolve[*cache.BugCache](repo, bug.Typename, bug.Namespace, repo.Bugs(), args)
}

func newBugSelectCommand() *cobra.Command {
env := execenv.NewEnv()

Expand All @@ -33,7 +38,7 @@ The complementary command is "git bug deselect" performing the opposite operatio
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugSelect(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

return cmd
Expand All @@ -51,7 +56,7 @@ func runBugSelect(env *execenv.Env, args []string) error {
return err
}

err = _select.Select(env.Backend, b.Id())
err = _select.Select(env.Backend, bug.Namespace, b.Id())
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions commands/bug/bug_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/cmdjson"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
Expand All @@ -32,7 +31,7 @@ func newBugShowCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugShow(env, options, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

flags := cmd.Flags()
Expand All @@ -50,7 +49,7 @@ func newBugShowCommand() *cobra.Command {
}

func runBugShow(env *execenv.Env, opts bugShowOptions, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -18,7 +16,7 @@ func newBugStatusCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugStatus(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

cmd.AddCommand(newBugStatusCloseCommand())
Expand All @@ -28,7 +26,7 @@ func newBugStatusCommand() *cobra.Command {
}

func runBugStatus(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_status_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -18,14 +16,14 @@ func newBugStatusCloseCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugStatusClose(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

return cmd
}

func runBugStatusClose(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_status_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -18,14 +16,14 @@ func newBugStatusOpenCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugStatusOpen(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

return cmd
}

func runBugStatusOpen(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_title.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bugcmd
import (
"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand All @@ -18,7 +16,7 @@ func newBugTitleCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugTitle(env, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

cmd.AddCommand(newBugTitleEditCommand())
Expand All @@ -27,7 +25,7 @@ func newBugTitleCommand() *cobra.Command {
}

func runBugTitle(env *execenv.Env, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions commands/bug/bug_title_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/spf13/cobra"

buginput "github.com/MichaelMure/git-bug/commands/bug/input"
"github.com/MichaelMure/git-bug/commands/bug/select"
"github.com/MichaelMure/git-bug/commands/completion"
"github.com/MichaelMure/git-bug/commands/execenv"
"github.com/MichaelMure/git-bug/util/text"
)
Expand All @@ -26,7 +24,7 @@ func newBugTitleEditCommand() *cobra.Command {
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runBugTitleEdit(env, options, args)
}),
ValidArgsFunction: completion.Bug(env),
ValidArgsFunction: BugCompletion(env),
}

flags := cmd.Flags()
Expand All @@ -41,7 +39,7 @@ func newBugTitleEditCommand() *cobra.Command {
}

func runBugTitleEdit(env *execenv.Env, opts bugTitleEditOptions, args []string) error {
b, args, err := _select.ResolveBug(env.Backend, args)
b, args, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
Expand Down

0 comments on commit d11ea5c

Please sign in to comment.