Virsion flag logic is added.

This commit is contained in:
Foil-hat-guy 2025-04-20 02:25:31 +03:00
parent f755414cb5
commit 1271256866
No known key found for this signature in database
GPG key ID: 221CC305A7B23591

37
main.go
View file

@ -6,9 +6,42 @@ import (
"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"
"github.com/spf13/pflag"
)
func init() {
pflag.ErrHelp = nil
versionFlagSet := pflag.NewFlagSet("version", pflag.ContinueOnError)
versionFlagSet.ParseErrorsWhitelist.UnknownFlags = true
versionFlagSet.SetOutput(nil)
versionIsAsked := versionFlagSet.BoolP("version", "v", false, "Prints version of this application.")
versionFlagSet.BoolP("help", "h", false, "") // This line is needed to supress (redefine) built-in help flag.
err := versionFlagSet.Parse(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if *versionIsAsked {
fmt.Println("Simple Serial version: " + Value)
os.Exit(0)
}
}
`
func main() {
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
out, err := cmd.Output()
@ -18,7 +51,7 @@ func main() {
}
version := string(out)
version = version[:len(version)-1]
content := header + version + "\""
content := warning + header + version + "\"" + code
ioutil.WriteFile("version.go", []byte(content), 0644)
}