Alexander Belanger 5 gadi atpakaļ
vecāks
revīzija
55d41a804e
3 mainītis faili ar 27 papildinājumiem un 0 dzēšanām
  1. 2 0
      .darwin.goreleaser.yml
  2. 2 0
      .goreleaser.yml
  3. 23 0
      cli/cmd/version.go

+ 2 - 0
.darwin.goreleaser.yml

@@ -4,6 +4,8 @@ before:
 builds:
   - id: "porter-cli"
     binary: porter
+    ldflags:
+    - -X 'github.com/porter-dev/porter/cli/cmd.Version={{.Version}}'
     env:
       - CGO_ENABLED=1
     dir: cli

+ 2 - 0
.goreleaser.yml

@@ -3,6 +3,8 @@ before:
     - go mod download
 builds:
   - id: "porter-cli"
+    ldflags:
+    - -X 'github.com/porter-dev/porter/cli/cmd.Version={{.Version}}'
     binary: porter
     dir: cli
     main: ./main.go

+ 23 - 0
cli/cmd/version.go

@@ -0,0 +1,23 @@
+package cmd
+
+import (
+	"fmt"
+
+	"github.com/spf13/cobra"
+)
+
+// Version will be linked by an ldflag during build
+var Version string = "dev"
+
+var versionCmd = &cobra.Command{
+	Use:     "version",
+	Aliases: []string{"v", "--version"},
+	Short:   "Prints the version of the Porter CLI",
+	Run: func(cmd *cobra.Command, args []string) {
+		fmt.Println(Version)
+	},
+}
+
+func init() {
+	rootCmd.AddCommand(versionCmd)
+}