60 lines
1021 B
Go
60 lines
1021 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/avanier/gitea-resource/pr"
|
|
"github.com/avanier/gitea-resource/util"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// prCmd represents the pr command
|
|
var prCmd = &cobra.Command{
|
|
Use: "pr",
|
|
Short: "Interact with Gitea Pull-Requests",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
var (
|
|
source util.STDINPayload
|
|
action string
|
|
dest string
|
|
err error
|
|
)
|
|
source = util.ParseSource(rootCmd.Flags())
|
|
action, err = rootCmd.Flags().GetString("action")
|
|
|
|
if err != nil {
|
|
util.HandleError(err)
|
|
}
|
|
|
|
dest, err = cmd.Flags().GetString("destination")
|
|
|
|
switch action {
|
|
case "check":
|
|
pr.List(source)
|
|
case "get":
|
|
pr.Get(source, dest)
|
|
case "put":
|
|
os.Exit(0)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
var (
|
|
Dest string
|
|
err error
|
|
pwd string
|
|
)
|
|
|
|
pwd, err = os.Getwd()
|
|
|
|
if err != nil {
|
|
util.HandleError(err)
|
|
}
|
|
|
|
rootCmd.AddCommand(prCmd)
|
|
prCmd.Flags().StringVarP(&Dest, "destination", "d", pwd, "Where to output the PR data")
|
|
prCmd.MarkFlagRequired("destination")
|
|
}
|