Virsion flag logic is added.
This commit is contained in:
parent
f755414cb5
commit
1271256866
1 changed files with 35 additions and 2 deletions
37
main.go
37
main.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue