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

This commit is contained in:
Ben 2021-05-19 12:57:56 -07:00
parent d656a9077b
commit 097dd25884

View file

@ -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
*/
// 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