diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-20 19:51:12 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-20 19:51:23 +0200 |
commit | 096397e51c1292b5e7247d5064236177d72ba9f4 (patch) | |
tree | 207f880e592c09a760abe00075a3a6e528b9c2a6 | |
parent | 7021e4041bbfb469797f78572a9432f3c93b171f (diff) | |
parent | 328252b063bfe128c27e5bac94650f62d101923d (diff) |
Merge branch 'main' into dev
-rwxr-xr-x | install.sh | 3 | ||||
-rw-r--r-- | main.go | 25 |
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)" @@ -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, ",") |