From 097dd25884fc792b8d30e967f346493c2bbad78c Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 19 May 2021 12:57:56 -0700 Subject: [PATCH] redefined how gh browse opens the repo. We now use the BaseRepo to extract the correct paths. This should make it easier to navigate to other directories within the repo using the repoUrl variable created --- pkg/cmd/browse/browse.go | 43 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/pkg/cmd/browse/browse.go b/pkg/cmd/browse/browse.go index 2880a75aa..e9478caff 100644 --- a/pkg/cmd/browse/browse.go +++ b/pkg/cmd/browse/browse.go @@ -1,41 +1,40 @@ package browse import ( + "fmt" + + "github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/pkg/cmdutil" "github.com/spf13/cobra" ) func NewCmdBrowse(f *cmdutil.Factory) *cobra.Command { - cmd := &cobra.Command{ - 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 + Long: "Work with GitHub in the browser", // 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 / runs function openInBrowser(cmd, f) - }, + }, } - cmdutil.EnableRepoOverride(cmd, f) // Q: what does this do??? - return cmd } func openInBrowser(cmd *cobra.Command, f *cmdutil.Factory) { - const root = "www.github.com" - f.Browser.Browse(root) + baseRepo, err := f.BaseRepo() + if err != nil { + fmt.Println("error") + } + // ATTN: add into the empty string where you want to go within the repo + repoUrl := ghrepo.GenerateRepoURL(baseRepo, "") + f.Browser.Browse(repoUrl) } - -/* -Moving forward, since we can open in the browser we need to discuss logic of arguments - -This includes: -1. Open the repo in browser with just "gh browse" -2. Make the help instruction display while opening using IOStreams -3. Find out how "cmd" stores args within, to be parsed -4. Make a table of all the possible inputs that are valid -5. Possibly work on error handling -6. Clarify table with client before moving forward with args - -*/ \ No newline at end of file +// Questions for tomorrow: +// if logged in / repo +// go to repo +// else if logged in / !repo +// go to profile +// else +// ? throw error / go to github home page