diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -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, ",") |