From 56488d26cd7069332ce8ac3c8e201a092ee16db6 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Fri, 26 Aug 2022 23:39:06 +0200 Subject: [PATCH] Support version flag --- .goreleaser.yaml | 2 ++ cli.go | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 092a00c..baa2819 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,6 +5,8 @@ before: builds: - main: ./cmd/go-zpl + ldflags: + - "-s -w -X github.com/kamilturek/go-zpl.version={{.Version}}" env: - CGO_ENABLED=0 goos: diff --git a/cli.go b/cli.go index bd280cd..4c37f1c 100644 --- a/cli.go +++ b/cli.go @@ -6,7 +6,12 @@ import ( "os" ) +var version string + func RunCLI() { + showVersion := flag.Bool("v", false, "version for go-zpl") + showVersionLong := flag.Bool("version", false, "version for go-zpl") + density := flag.Int("d", 8, "input label density [dpmm]") width := flag.Int("w", 4, "input label width [inch]") height := flag.Int("h", 6, "input label height [inch]") @@ -14,6 +19,11 @@ func RunCLI() { outputFormat := flag.String("f", "png", "output file format") flag.Parse() + if *showVersion || *showVersionLong { + fmt.Fprintln(os.Stdout, version) + os.Exit(0) + } + if err := Convert( WithInputFromArgs(flag.Args()), WithOutputPath(*outputPath),