From 68ce66801b5fb076e449d30c3dcb2867d7cd47b9 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 15 May 2021 21:09:13 -0700 Subject: [PATCH] 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 .! --- cmd/gh/main.go | 1 + pkg/cmd/browse/browse.go | 41 ++++++++++++++++++++-------------------- pkg/cmd/root/root.go | 4 +--- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index b9dc52858..93aa98575 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -45,6 +45,7 @@ const ( func main() { code := mainRun() os.Exit(int(code)) + } func mainRun() exitCode { diff --git a/pkg/cmd/browse/browse.go b/pkg/cmd/browse/browse.go index 049f2d9f0..b2b016e2a 100644 --- a/pkg/cmd/browse/browse.go +++ b/pkg/cmd/browse/browse.go @@ -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 ", - 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") + +} \ No newline at end of file diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 5c8ac4689..f4f44263c 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -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))