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

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