@@ -11,7 +11,7 @@ import (
1111
1212 "github.com/MakeNowJust/heredoc"
1313 "github.com/cli/cli/v2/api"
14- "github.com/cli/cli/v2/internal/ghinstance "
14+ "github.com/cli/cli/v2/internal/config "
1515 "github.com/cli/cli/v2/internal/ghrepo"
1616 "github.com/cli/cli/v2/pkg/cmdutil"
1717 "github.com/cli/cli/v2/pkg/iostreams"
@@ -30,6 +30,7 @@ type ViewOptions struct {
3030 BaseRepo func () (ghrepo.Interface , error )
3131 Browser browser
3232 Exporter cmdutil.Exporter
33+ Config func () (config.Config , error )
3334
3435 RepoArg string
3536 Web bool
@@ -42,6 +43,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
4243 HttpClient : f .HttpClient ,
4344 BaseRepo : f .BaseRepo ,
4445 Browser : f .Browser ,
46+ Config : f .Config ,
4547 }
4648
4749 cmd := & cobra.Command {
@@ -90,10 +92,18 @@ func viewRun(opts *ViewOptions) error {
9092 return err
9193 }
9294 } else {
93- var err error
9495 viewURL := opts .RepoArg
9596 if ! strings .Contains (viewURL , "/" ) {
96- currentUser , err := api .CurrentLoginName (apiClient , ghinstance .Default ())
97+ cfg , err := opts .Config ()
98+ if err != nil {
99+ return err
100+ }
101+ hostname , err := cfg .DefaultHost ()
102+ if err != nil {
103+ return err
104+ }
105+
106+ currentUser , err := api .CurrentLoginName (apiClient , hostname )
97107 if err != nil {
98108 return err
99109 }
0 commit comments