mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-22 19:51:58 +01:00
894a641ef8
Clean up docs Signed-off-by: jolheiser <john.olheiser@gmail.com> Add generated docs Signed-off-by: jolheiser <john.olheiser@gmail.com> Update go.sum Signed-off-by: jolheiser <john.olheiser@gmail.com> Fix remote parsing Signed-off-by: jolheiser <john.olheiser@gmail.com> Refactor and clean up Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/jolheiser/sip/pulls/29
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"gitea.com/jolheiser/sip/flag"
|
|
|
|
"github.com/skratchdot/open-golang/open"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var Open = cli.Command{
|
|
Name: "open",
|
|
Aliases: []string{"o"},
|
|
Usage: "Open a repository or issue/pull request",
|
|
Action: doOpen,
|
|
}
|
|
|
|
func doOpen(ctx *cli.Context) error {
|
|
if ctx.NArg() == 0 {
|
|
return open.Run(flag.FullURL())
|
|
}
|
|
|
|
arg := ctx.Args().First()
|
|
|
|
// Check if issue or PR
|
|
issue, err := strconv.ParseInt(arg, 10, 64)
|
|
if err == nil {
|
|
return open.Run(fmt.Sprintf("%s/issues/%d", flag.FullURL(), issue))
|
|
}
|
|
|
|
// Check if overriding repository (jolheiser/sip)
|
|
ownerRepoIssue := strings.Split(arg, "/")
|
|
if len(ownerRepoIssue) == 2 {
|
|
return open.Run(fmt.Sprintf("%s/%s", flag.FullURL(), arg))
|
|
}
|
|
|
|
// Check if both? (jolheiser/sip/1234)
|
|
if len(ownerRepoIssue) == 3 {
|
|
return open.Run(fmt.Sprintf("%s/%s/%s/issues/%s", flag.URL, ownerRepoIssue[0], ownerRepoIssue[1], ownerRepoIssue[2]))
|
|
}
|
|
|
|
return errors.New("unknown argument: leave blank to open current repo, pass issue/PR as #1234, or override repo as owner/repo")
|
|
}
|