Skip to content

Commit

Permalink
Merge pull request #13 from Syuparn/versioning
Browse files Browse the repository at this point in the history
add -v option
  • Loading branch information
Syuparn authored Feb 22, 2021
2 parents 64ffe2f + bcf78ef commit 39b0243
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ import (
)

var (
fileName = flag.String("f", "", "use template file")
runsREPL = flag.Bool("i", false, "run interactive REPL instead")
leftDelim = flag.String("ldelim", "{{", "specify left deliminater")
rightDelim = flag.String("rdelim", "}}", "specify right deliminater")
fileName = flag.String("f", "", "use template file")
runsREPL = flag.Bool("i", false, "run interactive REPL instead")
showsVersion = flag.Bool("v", false, "show version")
leftDelim = flag.String("ldelim", "{{", "specify left deliminater")
rightDelim = flag.String("rdelim", "}}", "specify right deliminater")
)

func main() {
flag.Parse()

if *showsVersion {
fmt.Println(versionStr())
return
}

tmpl := newTemplate(*leftDelim, *rightDelim)

if *runsREPL {
Expand Down
25 changes: 25 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"runtime/debug"
)

const defaultVersion = "development"

var version = ""

func versionStr() string {
// 1. if version is set (by goreleaser for example), show it
if version != "" {
return version
}

// 2. if runtime version is set (by go get for example), show it
info, ok := debug.ReadBuildInfo()
if ok {
return info.Main.Version
}

// 3. show default version
return defaultVersion
}

0 comments on commit 39b0243

Please sign in to comment.