@@ -6,16 +6,15 @@ import (
66	"log" 
77	"os" 
88	"os/exec" 
9- 	"strings" 
10- )
119
12- var  sha  =  flag .String ("sha" , "" , "SHA of current commit" )
10+ 	"github.com/StackExchange/dnscontrol/v4/pkg/version" 
11+ )
1312
1413var  goos  =  flag .String ("os" , "" , "OS to build (linux, windows, or darwin) Defaults to all." )
1514
1615func  main () {
1716	flag .Parse ()
18- 	flags  :=  fmt .Sprintf (`-s -w -X "github.com/StackExchange/dnscontrol/v4/pkg/version.version=%s"` , getVersion ())
17+ 	flags  :=  fmt .Sprintf (`-s -w -X "github.com/StackExchange/dnscontrol/v4/pkg/version.version=%s"` , version . Version ())
1918	pkg  :=  "github.com/StackExchange/dnscontrol/v4" 
2019
2120	build  :=  func (out , goos  string ) {
@@ -50,32 +49,3 @@ func main() {
5049		}
5150	}
5251}
53- 
54- func  getVersion () string  {
55- 	if  * sha  !=  ""  {
56- 		return  * sha 
57- 	}
58- 	// check teamcity build version 
59- 	if  v  :=  os .Getenv ("BUILD_VCS_NUMBER" ); v  !=  ""  {
60- 		return  v 
61- 	}
62- 	// check git 
63- 	cmd  :=  exec .Command ("git" , "rev-parse" , "HEAD" )
64- 	v , err  :=  cmd .CombinedOutput ()
65- 	if  err  !=  nil  {
66- 		return  "" 
67- 	}
68- 	ver  :=  strings .TrimSpace (string (v ))
69- 	// see if dirty 
70- 	cmd  =  exec .Command ("git" , "diff-index" , "--quiet" , "HEAD" , "--" )
71- 	err  =  cmd .Run ()
72- 	// exit status 1 indicates dirty tree 
73- 	if  err  !=  nil  {
74- 		if  err .Error () ==  "exit status 1"  {
75- 			ver  +=  "[dirty]" 
76- 		} else  {
77- 			log .Printf ("!%s!" , err .Error ())
78- 		}
79- 	}
80- 	return  ver 
81- }
0 commit comments