diff options
| -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, ",") | 
