summaryrefslogtreecommitdiffhomepage
path: root/internal/version
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-03-23 14:56:32 +0100
committerKujtim Hoxha <[email protected]>2025-03-23 15:00:12 +0100
commit7844cacb257b14087bcb12764466ee0eeeb1921b (patch)
treeccc9df7140e38e9fa55d190fc9e9f294e3987583 /internal/version
parent4b0ea68d7af9a6031a7ffda7ad66e0cb83315750 (diff)
downloadopencode-7844cacb257b14087bcb12764466ee0eeeb1921b.tar.gz
opencode-7844cacb257b14087bcb12764466ee0eeeb1921b.zip
add help
Diffstat (limited to 'internal/version')
-rw-r--r--internal/version/version.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/version/version.go b/internal/version/version.go
new file mode 100644
index 000000000..54c576f6c
--- /dev/null
+++ b/internal/version/version.go
@@ -0,0 +1,25 @@
+package version
+
+import "runtime/debug"
+
+// Build-time parameters set via -ldflags
+var Version = "unknown"
+
+// A user may install pug using `go install github.com/leg100/pug@latest`
+// without -ldflags, in which case the version above is unset. As a workaround
+// we use the embedded build version that *is* set when using `go install` (and
+// is only set for `go install` and not for `go build`).
+func init() {
+ info, ok := debug.ReadBuildInfo()
+ if !ok {
+ // < go v1.18
+ return
+ }
+ mainVersion := info.Main.Version
+ if mainVersion == "" || mainVersion == "(devel)" {
+ // bin not built using `go install`
+ return
+ }
+ // bin built using `go install`
+ Version = mainVersion
+}