diff options
| author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-15 11:40:17 +0200 | 
|---|---|---|
| committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-15 11:46:24 +0200 | 
| commit | 877bca73c901484a6a68813083ab21b8299cd10d (patch) | |
| tree | 0be484332d079e5ebdf922bacfa3741d61db77fe | |
| parent | d6021aaad84068c01b4e53f161d07f57b9357f43 (diff) | |
Add version flag
| -rw-r--r-- | main.go | 20 | 
1 files changed, 20 insertions, 0 deletions
| @@ -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) | 
