aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-20 19:51:12 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-20 19:51:23 +0200
commit096397e51c1292b5e7247d5064236177d72ba9f4 (patch)
tree207f880e592c09a760abe00075a3a6e528b9c2a6
parent7021e4041bbfb469797f78572a9432f3c93b171f (diff)
parent328252b063bfe128c27e5bac94650f62d101923d (diff)
Merge branch 'main' into dev
-rwxr-xr-xinstall.sh3
-rw-r--r--main.go25
2 files changed, 25 insertions, 3 deletions
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..01d592f
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+go install -ldflags "-X main.Version=$(git describe --tags 2>/dev/null)"
diff --git a/main.go b/main.go
index 0888e93..6ce5c29 100644
--- a/main.go
+++ b/main.go
@@ -11,7 +11,9 @@ package main
import (
"flag"
"fmt"
+ "os"
"os/exec"
+ "runtime/debug"
"strings"
"time"
@@ -42,12 +44,23 @@ var (
RunCommand []string
// Command will only run on files that have the Extensions extension
Extensions []string
-)
-
-const (
+ // Layout for timestamp of command
DateLayout string = "15:04:05"
+ // Version tag for wbr
+ Version string
)
+func GetVersion() string {
+ if Version != "" {
+ return Version
+ }
+ buildinfo, ok := debug.ReadBuildInfo()
+ if !ok {
+ panic("Could not read buildinfo to know package version.")
+ }
+ return buildinfo.Main.Version
+}
+
func CompileRun(fileName string) {
found := false
for _, Ext := range Extensions {
@@ -134,8 +147,14 @@ func main() {
rc := flag.String("r", "", "Command for running after build")
e := flag.String("e", "", "Filter watched files by suffix")
p := flag.String("p", ".", "Path to watch for files")
+ v := flag.Bool("v", false, "Show wbr version")
flag.Parse()
+ if *v {
+ fmt.Printf("wbr %s\n", GetVersion())
+ os.Exit(0)
+ }
+
BuildCommand = strings.Split(*bc, " ")
RunCommand = strings.Split(*rc, " ")
Extensions = strings.Split(*e, ",")