Browse Source

fail softly, as documented

tags/v1.1.3
AJ ONeal 7 months ago
parent
commit
d4628bd751
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      gitver.go

+ 10
- 4
gitver.go View File

@@ -6,7 +6,6 @@ import (
6 6
 	"bytes"
7 7
 	"fmt"
8 8
 	"go/format"
9
-	"log"
10 9
 	"os"
11 10
 	"text/template"
12 11
 	"time"
@@ -45,8 +44,13 @@ func main() {
45 44
 
46 45
 	v, err := gitver.ExecAndParse()
47 46
 	if nil != err {
48
-		log.Fatalf("Failed to get git version: %s\n", err)
49
-		os.Exit(exitCode)
47
+		fmt.Fprintf(os.Stderr, "Failed to get git version: %s\n", err)
48
+		if exitCode > 0 {
49
+			os.Exit(exitCode)
50
+		}
51
+		v = &gitver.Versions{
52
+			Timestamp: time.Now(),
53
+		}
50 54
 	}
51 55
 
52 56
 	// Create or overwrite the go file from template
@@ -89,8 +93,10 @@ var versionTpl = template.Must(template.New("").Parse(`// Code generated by go g
89 93
 package {{ .Package }}
90 94
 
91 95
 func init() {
96
+	{{ if .GitRev -}}
92 97
 	GitRev = "{{ .GitRev }}"
93
-  {{ if .Version -}}
98
+	{{ end -}}
99
+	{{ if .Version -}}
94 100
 	GitVersion = "{{ .Version }}"
95 101
 	{{ end -}}
96 102
 	GitTimestamp = "{{ .Timestamp }}"

Loading…
Cancel
Save