From bd8e535d4ab8b3842f4956d92af53e2cb2373668 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 5 Sep 2024 09:47:03 -0700 Subject: [PATCH] Some goreleaser improvements --- .goreleaser.yaml | 1 + cmd/yaakcli/main.go | 4 +++- cmd_root.go | 35 ++++++++++++++++++++++------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9505f95..0908ef3 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,5 +2,6 @@ version: 2 builds: - binary: yaakcli + main: ./cmd/yaakcli/main.go env: - CGO_ENABLED=0 diff --git a/cmd/yaakcli/main.go b/cmd/yaakcli/main.go index 46d6040..1c57d47 100644 --- a/cmd/yaakcli/main.go +++ b/cmd/yaakcli/main.go @@ -4,6 +4,8 @@ import ( "github.com/yaakapp/yaakcli" ) +var version = "dev" + func main() { - yaakcli.Execute() + yaakcli.Execute(version) } diff --git a/cmd_root.go b/cmd_root.go index ecb4a36..afd5ea0 100644 --- a/cmd_root.go +++ b/cmd_root.go @@ -6,22 +6,31 @@ import ( "os" ) -var rootCmd = &cobra.Command{ - Use: "plaak", - Short: "Develop plugins for Yaak", - Long: `Generate, build, and debug plugins for Yaak, the most intuitive desktop API client`, - Run: func(cmd *cobra.Command, args []string) { - println("Hello from Plaak") - }, -} +func rootCmd(version string) *cobra.Command { + var fVersion bool + cmd := &cobra.Command{ + Use: "plaak", + Short: "Develop plugins for Yaak", + Long: `Generate, build, and debug plugins for Yaak, the most intuitive desktop API client`, + Run: func(cmd *cobra.Command, args []string) { + if fVersion { + println(version) + os.Exit(0) + } + + checkErr(cmd.Help()) + }, + } + cmd.AddCommand(buildCmd) + cmd.AddCommand(generateCmd) + + cmd.Flags().BoolVar(&fVersion, "version", false, "Source directory to read from") -func init() { - rootCmd.AddCommand(buildCmd) - rootCmd.AddCommand(generateCmd) + return cmd } -func Execute() { - if err := rootCmd.Execute(); err != nil { +func Execute(version string) { + if err := rootCmd(version).Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) }