working on the browse view

This commit is contained in:
bchadwic 2021-05-12 16:02:14 -07:00
parent c42f6acbde
commit 602334f58a
4 changed files with 97 additions and 0 deletions

37
pkg/cmd/browse/browse.go Normal file
View file

@ -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 <command>",
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
}

View file

@ -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
}

View file

@ -0,0 +1 @@
package view

View file

@ -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))