diff --git a/command/root.go b/command/root.go index 19206b648..5eb6e930f 100644 --- a/command/root.go +++ b/command/root.go @@ -22,15 +22,11 @@ import ( "github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/internal/run" apiCmd "github.com/cli/cli/pkg/cmd/api" - gistCreateCmd "github.com/cli/cli/pkg/cmd/gist/create" + gistCmd "github.com/cli/cli/pkg/cmd/gist" issueCmd "github.com/cli/cli/pkg/cmd/issue" prCmd "github.com/cli/cli/pkg/cmd/pr" repoCmd "github.com/cli/cli/pkg/cmd/repo" - repoCloneCmd "github.com/cli/cli/pkg/cmd/repo/clone" - repoCreateCmd "github.com/cli/cli/pkg/cmd/repo/create" creditsCmd "github.com/cli/cli/pkg/cmd/repo/credits" - repoForkCmd "github.com/cli/cli/pkg/cmd/repo/fork" - repoViewCmd "github.com/cli/cli/pkg/cmd/repo/view" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/iostreams" "github.com/cli/cli/utils" @@ -123,15 +119,9 @@ func init() { return currentBranch, nil }, } - RootCmd.AddCommand(apiCmd.NewCmdApi(cmdFactory, nil)) - gistCmd := &cobra.Command{ - Use: "gist", - Short: "Create gists", - Long: `Work with GitHub gists.`, - } - RootCmd.AddCommand(gistCmd) - gistCmd.AddCommand(gistCreateCmd.NewCmdCreate(cmdFactory, nil)) + RootCmd.AddCommand(apiCmd.NewCmdApi(cmdFactory, nil)) + RootCmd.AddCommand(gistCmd.NewCmdGist(cmdFactory)) resolvedBaseRepo := func() (ghrepo.Interface, error) { httpClient, err := cmdFactory.HttpClient() @@ -162,15 +152,9 @@ func init() { repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo - RootCmd.AddCommand(repoCmd.Cmd) - repoCmd.Cmd.AddCommand(repoViewCmd.NewCmdView(&repoResolvingCmdFactory, nil)) - repoCmd.Cmd.AddCommand(repoForkCmd.NewCmdFork(&repoResolvingCmdFactory, nil)) - repoCmd.Cmd.AddCommand(repoCloneCmd.NewCmdClone(cmdFactory, nil)) - repoCmd.Cmd.AddCommand(repoCreateCmd.NewCmdCreate(cmdFactory, nil)) - repoCmd.Cmd.AddCommand(creditsCmd.NewCmdRepoCredits(&repoResolvingCmdFactory, nil)) - RootCmd.AddCommand(prCmd.NewCmdPR(&repoResolvingCmdFactory)) RootCmd.AddCommand(issueCmd.NewCmdIssue(&repoResolvingCmdFactory)) + RootCmd.AddCommand(repoCmd.NewCmdRepo(&repoResolvingCmdFactory)) RootCmd.AddCommand(creditsCmd.NewCmdCredits(cmdFactory, nil)) } diff --git a/pkg/cmd/gist/gist.go b/pkg/cmd/gist/gist.go new file mode 100644 index 000000000..ea10a8c40 --- /dev/null +++ b/pkg/cmd/gist/gist.go @@ -0,0 +1,19 @@ +package gist + +import ( + gistCreateCmd "github.com/cli/cli/pkg/cmd/gist/create" + "github.com/cli/cli/pkg/cmdutil" + "github.com/spf13/cobra" +) + +func NewCmdGist(f *cmdutil.Factory) *cobra.Command { + cmd := &cobra.Command{ + Use: "gist", + Short: "Create gists", + Long: `Work with GitHub gists.`, + } + + cmd.AddCommand(gistCreateCmd.NewCmdCreate(f, nil)) + + return cmd +} diff --git a/pkg/cmd/repo/repo.go b/pkg/cmd/repo/repo.go index 7de2e3ee7..551c96641 100644 --- a/pkg/cmd/repo/repo.go +++ b/pkg/cmd/repo/repo.go @@ -2,22 +2,40 @@ package repo import ( "github.com/MakeNowJust/heredoc" + repoCloneCmd "github.com/cli/cli/pkg/cmd/repo/clone" + repoCreateCmd "github.com/cli/cli/pkg/cmd/repo/create" + creditsCmd "github.com/cli/cli/pkg/cmd/repo/credits" + repoForkCmd "github.com/cli/cli/pkg/cmd/repo/fork" + repoViewCmd "github.com/cli/cli/pkg/cmd/repo/view" + "github.com/cli/cli/pkg/cmdutil" "github.com/spf13/cobra" ) -var Cmd = &cobra.Command{ - Use: "repo ", - Short: "Create, clone, fork, and view repositories", - Long: `Work with GitHub repositories`, - Example: heredoc.Doc(` - $ gh repo create - $ gh repo clone cli/cli - $ gh repo view --web - `), - Annotations: map[string]string{ - "IsCore": "true", - "help:arguments": ` -A repository can be supplied as an argument in any of the following formats: -- "OWNER/REPO" -- by URL, e.g. "https://github.com/OWNER/REPO"`}, +func NewCmdRepo(f *cmdutil.Factory) *cobra.Command { + cmd := &cobra.Command{ + Use: "repo ", + Short: "Create, clone, fork, and view repositories", + Long: `Work with GitHub repositories`, + Example: heredoc.Doc(` + $ gh repo create + $ gh repo clone cli/cli + $ gh repo view --web + `), + Annotations: map[string]string{ + "IsCore": "true", + "help:arguments": heredoc.Doc(` + A repository can be supplied as an argument in any of the following formats: + - "OWNER/REPO" + - by URL, e.g. "https://github.com/OWNER/REPO" + `), + }, + } + + cmd.AddCommand(repoViewCmd.NewCmdView(f, nil)) + cmd.AddCommand(repoForkCmd.NewCmdFork(f, nil)) + cmd.AddCommand(repoCloneCmd.NewCmdClone(f, nil)) + cmd.AddCommand(repoCreateCmd.NewCmdCreate(f, nil)) + cmd.AddCommand(creditsCmd.NewCmdRepoCredits(f, nil)) + + return cmd }