diff --git a/pkg/cmd/root/completion.go b/pkg/cmd/completion/completion.go similarity index 93% rename from pkg/cmd/root/completion.go rename to pkg/cmd/completion/completion.go index a96b69840..7c1ec46f0 100644 --- a/pkg/cmd/root/completion.go +++ b/pkg/cmd/completion/completion.go @@ -1,4 +1,4 @@ -package root +package completion import ( "errors" @@ -6,11 +6,11 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/pkg/cmdutil" - "github.com/cli/cli/pkg/iostreams" "github.com/spf13/cobra" ) -func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command { +func NewCmdCompletion(f *cmdutil.Factory) *cobra.Command { + io := f.IOStreams var shellType string cmd := &cobra.Command{ diff --git a/pkg/cmd/root/completion_test.go b/pkg/cmd/completion/completion_test.go similarity index 92% rename from pkg/cmd/root/completion_test.go rename to pkg/cmd/completion/completion_test.go index 505a65319..d75c71398 100644 --- a/pkg/cmd/root/completion_test.go +++ b/pkg/cmd/completion/completion_test.go @@ -1,9 +1,10 @@ -package root +package completion import ( "strings" "testing" + "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/iostreams" "github.com/google/shlex" "github.com/spf13/cobra" @@ -45,7 +46,10 @@ func TestNewCmdCompletion(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { io, _, stdout, stderr := iostreams.Test() - completeCmd := NewCmdCompletion(io) + f := &cmdutil.Factory{ + IOStreams: io, + } + completeCmd := NewCmdCompletion(f) rootCmd := &cobra.Command{Use: "gh"} rootCmd.AddCommand(completeCmd) diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 8f0b45817..8549ac3bc 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -13,6 +13,7 @@ import ( aliasCmd "github.com/cli/cli/pkg/cmd/alias" apiCmd "github.com/cli/cli/pkg/cmd/api" authCmd "github.com/cli/cli/pkg/cmd/auth" + completionCmd "github.com/cli/cli/pkg/cmd/completion" configCmd "github.com/cli/cli/pkg/cmd/config" "github.com/cli/cli/pkg/cmd/factory" gistCmd "github.com/cli/cli/pkg/cmd/gist" @@ -88,7 +89,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command { cmd.AddCommand(configCmd.NewCmdConfig(f)) cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil)) cmd.AddCommand(gistCmd.NewCmdGist(f)) - cmd.AddCommand(NewCmdCompletion(f.IOStreams)) + cmd.AddCommand(completionCmd.NewCmdCompletion(f)) // Help topics cmd.AddCommand(NewHelpTopic("environment"))