diff --git a/pkg/cmd/browse/browse.go b/pkg/cmd/browse/browse.go new file mode 100644 index 000000000..bdceb2056 --- /dev/null +++ b/pkg/cmd/browse/browse.go @@ -0,0 +1,37 @@ +package browse + +import ( + "github.com/MakeNowJust/heredoc" + cmdView "github.com/cli/cli/pkg/cmd/browse/view" + "github.com/cli/cli/pkg/cmdutil" + "github.com/spf13/cobra" +) + +func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command { + cmd := &cobra.Command{ + Use: "issue ", + Short: "", + Long: `Open GitHub in the browser`, + Example: heredoc.Doc(` + $ gh browse issue "217" + $ gh browse file "src/main.java" + $ gh browse branch "master" + `), + Annotations: map[string]string{ + "IsCore": "true", // what is this? + "help:arguments": heredoc.Doc(` + Branch names, pr numbers, issue numbers, and file paths + can be supplied as arguments in the following formats: + - by number, e.g. “123”; or + - by description, e.g. “index.js” + + `), + }, + } + + cmdutil.EnableRepoOverride(cmd, f) // what is this? + + cmd.AddCommand(cmdView.NewCmdView(f, nil)) + + return cmd +} diff --git a/pkg/cmd/browse/view/view.go b/pkg/cmd/browse/view/view.go index e69de29bb..86308f2b6 100644 --- a/pkg/cmd/browse/view/view.go +++ b/pkg/cmd/browse/view/view.go @@ -0,0 +1,57 @@ +package view + +import ( + "net/http" + "time" + + "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/internal/ghrepo" + "github.com/cli/cli/pkg/cmdutil" + "github.com/cli/cli/pkg/iostreams" + "github.com/spf13/cobra" +) + +type browser interface { + Browse(string) error +} + +type ViewOptions struct { + HttpClient func() (*http.Client, error) + IO *iostreams.IOStreams + BaseRepo func() (ghrepo.Interface, error) + Browser browser + + SelectorArg string + WebMode bool + Comments bool + Exporter cmdutil.Exporter + + Now func() time.Time +} + +func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { + + cmd := &cobra.Command{ + Use: "view", + Short: "View in browser", + Long: heredoc.Doc(` + Open the repository page in the browser + `), + Args: cobra.ExactArgs(1), + // RunE: func(cmd *cobra.Command, args []string) error { + // // support `-R, --repo` override + // opts.BaseRepo = f.BaseRepo + + // if len(args) > 0 { + // opts.SelectorArg = args[0] + // } + + // if runF != nil { + // return runF(opts) + // } + // return viewRun(opts) + // }, + } + + return cmd +} diff --git a/pkg/cmd/browse/view/view_test.go b/pkg/cmd/browse/view/view_test.go index e69de29bb..ef1189a10 100644 --- a/pkg/cmd/browse/view/view_test.go +++ b/pkg/cmd/browse/view/view_test.go @@ -0,0 +1 @@ +package view diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index b60d16012..6c4d1a0de 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -11,6 +11,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" + browseCmd "github.com/cli/cli/pkg/cmd/browse" completionCmd "github.com/cli/cli/pkg/cmd/completion" configCmd "github.com/cli/cli/pkg/cmd/config" "github.com/cli/cli/pkg/cmd/factory" @@ -76,6 +77,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command { cmd.AddCommand(actionsCmd.NewCmdActions(f)) cmd.AddCommand(aliasCmd.NewCmdAlias(f)) cmd.AddCommand(authCmd.NewCmdAuth(f)) + cmd.AddCommand(browseCmd.NewCmdBrowse(f)) cmd.AddCommand(configCmd.NewCmdConfig(f)) cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil)) cmd.AddCommand(gistCmd.NewCmdGist(f))