Add build script, generate version string on build time, modify usage and add version info
This commit is contained in:
parent
8538df7a14
commit
9364b82e08
4 changed files with 23 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -22,4 +22,4 @@ go.work
|
||||||
go.work.sum
|
go.work.sum
|
||||||
|
|
||||||
# build
|
# build
|
||||||
ass
|
ass_v*
|
||||||
|
|
10
args.go
10
args.go
|
@ -5,6 +5,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configFilepath string
|
var configFilepath string
|
||||||
|
@ -12,6 +13,15 @@ var privateKeyFilepath string
|
||||||
var logFlag bool
|
var logFlag bool
|
||||||
|
|
||||||
func ParseCommandline() bool {
|
func ParseCommandline() bool {
|
||||||
|
flag.Usage = func () {
|
||||||
|
fmt.Println(`Usage: ass -config <string> -pkey <string> [-log]
|
||||||
|
|
||||||
|
-config <string> The path to the config file (required)
|
||||||
|
-pkey <string> The path to the private key file (required)
|
||||||
|
-log Enable logging of messages
|
||||||
|
|
||||||
|
version:`, Version)
|
||||||
|
}
|
||||||
flag.StringVar(&configFilepath, "config", "", "The path to the config file (required)")
|
flag.StringVar(&configFilepath, "config", "", "The path to the config file (required)")
|
||||||
flag.StringVar(&privateKeyFilepath, "pkey", "", "The path to the private key file (required)")
|
flag.StringVar(&privateKeyFilepath, "pkey", "", "The path to the private key file (required)")
|
||||||
flag.BoolVar(&logFlag, "log", false, "Enable logging of messages")
|
flag.BoolVar(&logFlag, "log", false, "Enable logging of messages")
|
||||||
|
|
10
build.sh
Executable file
10
build.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
ver="$(git rev-parse --short HEAD)"
|
||||||
|
|
||||||
|
if ! git diff-index --quiet HEAD
|
||||||
|
then
|
||||||
|
ver="${ver}-dev"
|
||||||
|
fi
|
||||||
|
|
||||||
|
go build -ldflags="-X 'main.Version=${ver}'" -o ass_v${ver}
|
2
main.go
2
main.go
|
@ -5,6 +5,8 @@ package main
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
|
var Version = "dev"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if ParseCommandline() {
|
if ParseCommandline() {
|
||||||
ParseConfig(configFilepath)
|
ParseConfig(configFilepath)
|
||||||
|
|
Reference in a new issue