From a9236c518689ced86908fee365b44c1f56367256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Cola=C3=A7o?= Date: Sun, 27 Oct 2024 17:49:54 +0100 Subject: [PATCH] feat: Version sub command Add sub command to print megophone version --- .goreleaser.yaml | 3 +++ cmd/root.go | 1 + cmd/version.go | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 cmd/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b67522f..9f55602 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -3,6 +3,9 @@ builds: - binary: megophone env: - CGO_ENABLED=0 + ldflags: + - -X cmd.Version={{.Version}} + aurs: - name: megophone-bin homepage: "https://github.com/coolapso/megophone" diff --git a/cmd/root.go b/cmd/root.go index 72551d9..92d9fe5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -198,6 +198,7 @@ func init() { rootCmd.Flags().BoolP("m-only", "m", false, "Post to Mastodon Only") rootCmd.Flags().StringP("media-path", "p", "", "Path of media to be uploaded") rootCmd.AddCommand(configure) + rootCmd.AddCommand(versionCmd) } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..c924901 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + Version = "DEV" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print megophone version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Megophone %s\n", Version) + }, +}