Skip to content

Commit 68ce668

Browse files
committed
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 .!
1 parent e905133 commit 68ce668

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

cmd/gh/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
func main() {
4646
code := mainRun()
4747
os.Exit(int(code))
48+
4849
}
4950

5051
func mainRun() exitCode {

pkg/cmd/browse/browse.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
package browse
22

33
import (
4-
"github.com/MakeNowJust/heredoc"
4+
"fmt"
5+
"os"
6+
57
"github.com/cli/cli/pkg/cmdutil"
8+
"github.com/cli/cli/pkg/iostreams"
69
"github.com/spf13/cobra"
710
)
811

912
func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command {
13+
1014
cmd := &cobra.Command{
11-
Use: "browse <command>",
12-
Short: "",
13-
Long: `Open GitHub in the browser`,
14-
Example: heredoc.Doc(`
15-
$ gh browse issue "217"
16-
$ gh browse file "src/main.java"
17-
$ gh browse branch "master"
18-
`),
19-
Annotations: map[string]string{
20-
"IsCore": "true",
21-
"help:arguments": heredoc.Doc(`
22-
Branch names, pr numbers, issue numbers, and file paths
23-
can be supplied as arguments in the following formats:
24-
- by number, e.g. “123”; or
25-
- by description, e.g. “index.js”
26-
27-
`),
28-
},
15+
Long: "Hello world", // displays when you are on the help page of this command
16+
Short: "Open GitHub in the browser", // displays in the gh root help
17+
Use: "browse", // necessary!!! This is the cmd that gets passed on the prompt
18+
Run: func(cmd *cobra.Command, args []string) { // run gets rid of the usage
19+
openInBrowser()
20+
},
2921
}
3022

31-
cmdutil.EnableRepoOverride(cmd, f)
32-
23+
cmdutil.EnableRepoOverride(cmd, f)
3324

3425
return cmd
3526
}
27+
28+
func openInBrowser() {
29+
fmt.Println("");
30+
IO,_,_,_ := iostreams.Test() // why is this called test? is it to be used for the final product?
31+
browser := cmdutil.NewBrowser(os.Getenv("BROWSER"), IO.Out, IO.ErrOut)
32+
browser.Browse("www.github.com")
33+
34+
}

pkg/cmd/root/root.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package root
22

33
import (
44
"net/http"
5-
"fmt"
65

76
"github.com/MakeNowJust/heredoc"
87
"github.com/cli/cli/api"
@@ -95,8 +94,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
9594
repoResolvingCmdFactory := *f
9695
repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f)
9796

98-
fmt.Println("making browse command");
99-
cmd.AddCommand(browseCmd.NewCmdBrowse(f))
97+
cmd.AddCommand(browseCmd.NewCmdBrowse(f)) // adds to the commands Commands()
10098
cmd.AddCommand(prCmd.NewCmdPR(&repoResolvingCmdFactory))
10199
cmd.AddCommand(issueCmd.NewCmdIssue(&repoResolvingCmdFactory))
102100
cmd.AddCommand(releaseCmd.NewCmdRelease(&repoResolvingCmdFactory))

0 commit comments

Comments
 (0)