From 100790526b2d5ab2f95d748b4d294bb71817f222 Mon Sep 17 00:00:00 2001 From: daveberrys <84567826+daveberrys@users.noreply.github.com> Date: Sat, 18 Jul 2026 02:15:06 +0800 Subject: [PATCH] browse optional print --- src/cmd/browse/issues.go | 11 +++++++++-- src/cmd/browse/pr.go | 11 +++++++++-- src/cmd/browse/root.go | 11 +++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/cmd/browse/issues.go b/src/cmd/browse/issues.go index 209a7ca..d110f43 100644 --- a/src/cmd/browse/issues.go +++ b/src/cmd/browse/issues.go @@ -2,6 +2,7 @@ package browse import ( "strings" + "fmt" "github.com/daveberrys/guh/src/utils" "github.com/spf13/cobra" @@ -9,12 +10,18 @@ import ( ) var issuesCmd = &cobra.Command{ - Use: "issues", - Short: "Opens a browser to the issues page.", + Use: "issues [print]", + Short: "Opens a browser to the issues page. If 'print' is true, prints the URL instead.", RunE: func(cmd *cobra.Command, args []string) error { url, err := utils.RunGit(true, "remote", "get-url", "origin") if err != nil { return err } + url = strings.TrimSuffix(url, ".git") + if len(args) > 0 && args[0] == "print" { + fmt.Println(url + "/issues") + return nil + } + return browser.OpenURL(url + "/issues") }, } diff --git a/src/cmd/browse/pr.go b/src/cmd/browse/pr.go index 3df1ec8..9078b60 100644 --- a/src/cmd/browse/pr.go +++ b/src/cmd/browse/pr.go @@ -2,6 +2,7 @@ package browse import ( "strings" + "fmt" "github.com/daveberrys/guh/src/utils" "github.com/spf13/cobra" @@ -9,12 +10,18 @@ import ( ) var prCmd = &cobra.Command{ - Use: "pr", - Short: "Opens a browser to the PRs page.", + Use: "pr [print]", + Short: "Opens a browser to the PRs page. If 'print' is true, prints the URL instead.", RunE: func(cmd *cobra.Command, args []string) error { url, err := utils.RunGit(true, "remote", "get-url", "origin") if err != nil { return err } + url = strings.TrimSuffix(url, ".git") + if len(args) > 0 && args[0] == "print" { + fmt.Println(url + "/pulls") + return nil + } + return browser.OpenURL(url + "/pulls") }, } diff --git a/src/cmd/browse/root.go b/src/cmd/browse/root.go index 57e3433..5560bf4 100644 --- a/src/cmd/browse/root.go +++ b/src/cmd/browse/root.go @@ -2,6 +2,7 @@ package browse import ( "strings" + "fmt" "github.com/daveberrys/guh/src/cmd" "github.com/daveberrys/guh/src/utils" @@ -16,12 +17,18 @@ func init() { } var createCmd = &cobra.Command{ - Use: "browse", - Short: "Opens a browser to the repository.", + Use: "browse [print]", + Short: "Opens a browser to the repository. If 'print' is true, prints the URL instead.", RunE: func(cmd *cobra.Command, args []string) error { url, err := utils.RunGit(true, "remote", "get-url", "origin") if err != nil { return err } + url = strings.TrimSuffix(url, ".git") + if len(args) > 0 && args[0] == "print" { + fmt.Println(url) + return nil + } + return browser.OpenURL(url) }, } \ No newline at end of file