From 877bca73c901484a6a68813083ab21b8299cd10d Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Oct 2024 11:40:17 +0200 Subject: Add version flag --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index e197b10..f21b32c 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "os/exec" + "runtime/debug" "strings" "github.com/fsnotify/fsnotify" @@ -37,8 +38,21 @@ var ( RunCommand []string // Command will only run on files that have the Ext extension Ext string + // 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) { if !strings.HasSuffix(fileName, Ext) { return @@ -116,8 +130,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) + } + if *bc == "" { fmt.Println("flag is required: -b") os.Exit(1) -- cgit v1.2.3