version/main.go
2025-04-20 02:43:47 +03:00

42 lines
741 B
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
const warning = "//WARNING! DO NOT EDIT THIS FILE BY HAND. IT IS AUTO GENERATED.\n"
const header = "package main\nconst gitVersion = \""
const code = `
import (
"fmt"
"os"
)
func init() {
for _, arg := range os.Args {
if arg == "-v" || arg == "--version" {
fmt.Println(gitVersion)
os.Exit(0)
}
}
}
`
func main() {
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
out, err := cmd.Output()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
version := string(out)
version = version[:len(version)-1]
content := warning + header + version + "\"" + code
ioutil.WriteFile("version.go", []byte(content), 0644)
}