mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-07 07:43:30 +00:00
add --version flag
ensure version is injected at build time in Taskfile/makefile
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -15,6 +16,21 @@ import (
|
||||
udpproxy "github.com/onyx-and-iris/q3rcon-proxy"
|
||||
)
|
||||
|
||||
var version string // Version holds the application version, set at build time using ldflags.
|
||||
|
||||
// versionFromBuild retrieves the version information from the build metadata.
|
||||
func versionFromBuild() string {
|
||||
if version != "" {
|
||||
return version
|
||||
}
|
||||
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "(unable to read version)"
|
||||
}
|
||||
return strings.Split(info.Main.Version, "-")[0]
|
||||
}
|
||||
|
||||
// proxyConfig holds the configuration for a single UDP proxy server.
|
||||
type proxyConfig struct {
|
||||
proxyHost string
|
||||
@@ -24,9 +40,14 @@ type proxyConfig struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
cli.VersionPrinter = func(cmd *cli.Command) {
|
||||
fmt.Printf("q3rcon-proxy version: %s\n", cmd.Root().Version)
|
||||
}
|
||||
|
||||
cmd := &cli.Command{
|
||||
Name: "q3rcon-proxy",
|
||||
Usage: "A Quake 3 RCON proxy server",
|
||||
Name: "q3rcon-proxy",
|
||||
Usage: "A Quake 3 RCON proxy server",
|
||||
Version: versionFromBuild(),
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "proxy-host",
|
||||
@@ -111,7 +132,9 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
log.Fatal(cmd.Run(context.Background(), os.Args))
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// launchProxy initialises the UDP proxy server with the given configuration.
|
||||
|
||||
Reference in New Issue
Block a user