diff --git a/go.mod b/go.mod index 83b1fde..ea085ed 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/niklasfasching/go-org -go 1.17 +go 1.18 require ( github.com/alecthomas/chroma v0.10.0 diff --git a/main.go b/main.go index 94b710f..4cb20fa 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "runtime/debug" "strings" "github.com/alecthomas/chroma" @@ -37,6 +38,8 @@ func main() { render(args) case "blorg": runBlorg(args) + case "version": + printVersion() default: log.Fatal(usage) } @@ -130,3 +133,19 @@ func highlightCodeBlock(source, lang string, inline bool) string { } return `
` + "\n" + w.String() + "\n" + `
` } + +func printVersion() { + bi, ok := debug.ReadBuildInfo() + if !ok { + log.Fatal("not build info available") + } + revision, modified := "", false + for _, s := range bi.Settings { + if s.Key == "vcs.revision" { + revision = s.Value + } else if s.Key == "vcs.modified" { + modified = s.Value == "true" + } + } + log.Printf("%s (modified: %v)", revision, modified) +}