summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.goreleaser.yaml4
-rw-r--r--cmd/main.go9
-rw-r--r--cmd/version.go40
-rw-r--r--flyscrape.go2
4 files changed, 52 insertions, 3 deletions
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 0f7bc18..da630a7 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -13,6 +13,7 @@ builds:
- CXX=x86_64-linux-gnu-g++
ldflags:
- -s -w
+ - -X github.com/philippta/flyscrape.Version={{.Tag}}
flags:
- -mod=readonly
tags:
@@ -33,6 +34,7 @@ builds:
- CXX=aarch64-linux-gnu-g++
ldflags:
- -s -w
+ - -X github.com/philippta/flyscrape.Version={{.Tag}}
flags:
- -mod=readonly
tags:
@@ -55,6 +57,7 @@ builds:
- CXX=o64-clang++
ldflags:
- -s -w
+ - -X github.com/philippta/flyscrape.Version={{.Tag}}
flags:
- -mod=readonly
tags:
@@ -75,6 +78,7 @@ builds:
- CXX=oa64-clang++
ldflags:
- -s -w
+ - -X github.com/philippta/flyscrape.Version={{.Tag}}
flags:
- -mod=readonly
tags:
diff --git a/cmd/main.go b/cmd/main.go
index b4f8d1d..20210be 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -40,6 +40,8 @@ func (m *Main) Run(args []string) error {
return (&RunCommand{}).Run(args)
case "dev":
return (&DevCommand{}).Run(args)
+ case "version":
+ return (&VersionCommand{}).Run(args)
default:
if cmd == "" || cmd == "help" || strings.HasPrefix(cmd, "-") {
m.Usage()
@@ -59,8 +61,9 @@ Usage:
Commands:
- new creates a sample scraping script
- run runs a scraping script
- dev watches and re-runs a scraping script
+ new creates a sample scraping script
+ run runs a scraping script
+ dev watches and re-runs a scraping script
+ version prints the version
`[1:])
}
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
+}
diff --git a/flyscrape.go b/flyscrape.go
index d7aa8f8..057eb08 100644
--- a/flyscrape.go
+++ b/flyscrape.go
@@ -17,6 +17,8 @@ import (
"github.com/tidwall/sjson"
)
+var Version string
+
func Run(file string, overrides map[string]any) error {
src, err := os.ReadFile(file)
if err != nil {