From 8b7425e58909cdfa458ca00a10efc95f197bfb0b Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 8 Jan 2024 17:48:37 +0100 Subject: Add version command (#29) --- cmd/version.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cmd/version.go (limited to 'cmd/version.go') diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..bb1e453 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,40 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package cmd + +import ( + "fmt" + "runtime/debug" + + "github.com/philippta/flyscrape" +) + +type VersionCommand struct{} + +func (c *VersionCommand) Run(args []string) error { + info, ok := debug.ReadBuildInfo() + if !ok { + return fmt.Errorf("no build info found") + } + + var os, arch, version string + for _, setting := range info.Settings { + switch setting.Key { + case "GOARCH": + arch = setting.Value + case "GOOS": + os = setting.Value + case "vcs.revision": + version = "v0.0.0-" + setting.Value + } + } + + if flyscrape.Version != "" { + version = flyscrape.Version + } + + fmt.Printf("flyscrape %s %s/%s\n", version, os, arch) + return nil +} -- cgit v1.2.3