diff --git a/.goreleaser.yml b/.goreleaser.yml index 16ee56e..f94bdc5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -8,6 +8,7 @@ archives: format: zip builds: - id: webhook-go + ldflags: -s -w -X 'github.com/voxpupuli/webhook-go/cmd.version={{.Version}}' env: - CGO_ENABLED=0 goos: @@ -30,7 +31,7 @@ release: owner: voxpupuli name: webhook-go name_template: "Release v{{.Version}}" - prerelease: false + prerelease: auto checksum: name_template: 'checksums.txt' snapshot: diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..4b52c0d --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/voxpupuli/webhook-go/config" +) + +var cfgFile string + +var version = "0.0.0" + +var rootCmd = &cobra.Command{ + Use: "webhook-go", + Version: version, + Short: "API Server for providing r10k/g10k as a web service", + Long: `Provides an API service that parses git-based webhook + requests, executing r10k deployments based on the payload and + API endpoint.`, +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func init() { + cobra.OnInitialize(initConfig) + + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./webhook.yml)") +} + +func initConfig() { + if cfgFile != "" { + config.Init(&cfgFile) + } else { + config.Init(nil) + } +} diff --git a/cmd/server.go b/cmd/server.go new file mode 100644 index 0000000..ca73c43 --- /dev/null +++ b/cmd/server.go @@ -0,0 +1,36 @@ +/* +Copyright © 2022 NAME HERE + +*/ +package cmd + +import ( + "github.com/spf13/cobra" + "github.com/voxpupuli/webhook-go/server" +) + +// serverCmd represents the server command +var serverCmd = &cobra.Command{ + Use: "server", + Short: "Start the Webhook-go server", + Long: ``, + Run: startServer, +} + +func init() { + rootCmd.AddCommand(serverCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // serverCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + +func startServer(cmd *cobra.Command, args []string) { + server.Init() +}