Skip to content

Commit

Permalink
pass resolving baserepo into newcmdview
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Jul 23, 2020
1 parent d92c80b commit b9ce1a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
31 changes: 30 additions & 1 deletion command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,37 @@ func init() {
RootCmd.AddCommand(gistCmd)
gistCmd.AddCommand(gistCreateCmd.NewCmdCreate(cmdFactory, nil))

resolvedBaseRepo := func() (ghrepo.Interface, error) {
httpClient, err := cmdFactory.HttpClient()
if err != nil {
return nil, err
}

apiClient := api.NewClientFromHTTP(httpClient)

ctx := context.New()
remotes, err := ctx.Remotes()
if err != nil {
return nil, err
}
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "")
if err != nil {
return nil, err
}
baseRepo, err := repoContext.BaseRepo()
if err != nil {
return nil, err
}

return baseRepo, nil
}

repoResolvingCmdFactory := *cmdFactory

repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo

RootCmd.AddCommand(repoCmd)
repoCmd.AddCommand(repoViewCmd.NewCmdView(cmdFactory, nil))
repoCmd.AddCommand(repoViewCmd.NewCmdView(&repoResolvingCmdFactory, nil))
}

// RootCmd is the entry point of command-line execution
Expand Down
26 changes: 1 addition & 25 deletions pkg/cmd/repo/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/api"
"github.com/cli/cli/context"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
Expand All @@ -30,30 +29,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
opts := ViewOptions{
IO: f.IOStreams,
HttpClient: f.HttpClient,
BaseRepo: func() (ghrepo.Interface, error) {
httpClient, err := f.HttpClient()
if err != nil {
return nil, err
}

apiClient := api.NewClientFromHTTP(httpClient)

ctx := context.New()
remotes, err := ctx.Remotes()
if err != nil {
return nil, err
}
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "")
if err != nil {
return nil, err
}
baseRepo, err := repoContext.BaseRepo()
if err != nil {
return nil, err
}

return baseRepo, nil
},
BaseRepo: f.BaseRepo,
}

cmd := &cobra.Command{
Expand Down

0 comments on commit b9ce1a1

Please sign in to comment.