Browse Source

fail softly, as documented

master v1.1.3
AJ ONeal 5 years ago
parent
commit
d4628bd751
  1. 14
      gitver.go

14
gitver.go

@ -6,7 +6,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/format" "go/format"
"log"
"os" "os"
"text/template" "text/template"
"time" "time"
@ -45,8 +44,13 @@ func main() {
v, err := gitver.ExecAndParse() v, err := gitver.ExecAndParse()
if nil != err { if nil != err {
log.Fatalf("Failed to get git version: %s\n", err)
os.Exit(exitCode)
fmt.Fprintf(os.Stderr, "Failed to get git version: %s\n", err)
if exitCode > 0 {
os.Exit(exitCode)
}
v = &gitver.Versions{
Timestamp: time.Now(),
}
} }
// Create or overwrite the go file from template // Create or overwrite the go file from template
@ -89,8 +93,10 @@ var versionTpl = template.Must(template.New("").Parse(`// Code generated by go g
package {{ .Package }} package {{ .Package }}
func init() { func init() {
{{ if .GitRev -}}
GitRev = "{{ .GitRev }}" GitRev = "{{ .GitRev }}"
{{ if .Version -}}
{{ end -}}
{{ if .Version -}}
GitVersion = "{{ .Version }}" GitVersion = "{{ .Version }}"
{{ end -}} {{ end -}}
GitTimestamp = "{{ .Timestamp }}" GitTimestamp = "{{ .Timestamp }}"

Loading…
Cancel
Save