Initial commit

This commit is contained in:
Alexis Vanier
2020-01-09 17:06:03 -05:00
committed by Alexis Vanier
commit ebbf79ce68
23 changed files with 1443 additions and 0 deletions

59
cmd/pr.go Normal file
View File

@@ -0,0 +1,59 @@
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")
}

47
cmd/root.go Normal file
View File

@@ -0,0 +1,47 @@
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
action string
cfgFile string
verbose bool
inputFile string
showVersion bool
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gitea-resource",
Short: "Do things with Gitea from Concourse",
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVarP(&action, "action", "a", "check", "Concourse resource action to perform. May be check, in, or out.")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Prints out debug messages.")
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "V", false, "Prints the version and exit.")
rootCmd.PersistentFlags().StringVarP(&inputFile, "file", "F", "", "Consume input from file instead of stdin")
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
viper.AutomaticEnv() // read in environment variables that match
}