We got the browser to open on gh browse, now we're working towards making it specific to the argument passed in. Mini wingit add .!

This commit is contained in:
Ben 2021-05-15 21:09:13 -07:00
parent e905133068
commit 68ce66801b
3 changed files with 22 additions and 24 deletions

View file

@ -45,6 +45,7 @@ const (
func main() {
code := mainRun()
os.Exit(int(code))
}
func mainRun() exitCode {

View file

@ -1,35 +1,34 @@
package browse
import (
"github.com/MakeNowJust/heredoc"
"fmt"
"os"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/spf13/cobra"
)
func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "browse <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",
"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
`),
},
Long: "Hello world", // displays when you are on the help page of this command
Short: "Open GitHub in the browser", // displays in the gh root help
Use: "browse", // necessary!!! This is the cmd that gets passed on the prompt
Run: func(cmd *cobra.Command, args []string) { // run gets rid of the usage
openInBrowser()
},
}
cmdutil.EnableRepoOverride(cmd, f)
cmdutil.EnableRepoOverride(cmd, f)
return cmd
}
func openInBrowser() {
fmt.Println("");
IO,_,_,_ := iostreams.Test() // why is this called test? is it to be used for the final product?
browser := cmdutil.NewBrowser(os.Getenv("BROWSER"), IO.Out, IO.ErrOut)
browser.Browse("www.github.com")
}

View file

@ -2,7 +2,6 @@ package root
import (
"net/http"
"fmt"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/api"
@ -95,8 +94,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
repoResolvingCmdFactory := *f
repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f)
fmt.Println("making browse command");
cmd.AddCommand(browseCmd.NewCmdBrowse(f))
cmd.AddCommand(browseCmd.NewCmdBrowse(f)) // adds to the commands Commands()
cmd.AddCommand(prCmd.NewCmdPR(&repoResolvingCmdFactory))
cmd.AddCommand(issueCmd.NewCmdIssue(&repoResolvingCmdFactory))
cmd.AddCommand(releaseCmd.NewCmdRelease(&repoResolvingCmdFactory))