browse optional print

This commit is contained in:
daveberrys committed 2026-07-18 02:15:06 +08:00
1 parent f380c3c581
commit 100790526b
3 files changed
+27 -6

No files matched your search

+9 -2
View File
@@ -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")
},
}
+9 -2
View File
@@ -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")
},
}
+9 -2
View File
@@ -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)
},
}