From f000606c94b93cb8d7ba89b8b66e44d03c37ebd8 Mon Sep 17 00:00:00 2001 From: Mark Pashmfouroush Date: Thu, 2 May 2024 13:23:18 +0100 Subject: [PATCH] misc: add --version flag Signed-off-by: Mark Pashmfouroush --- .github/workflows/go-build.yaml | 2 +- go.mod | 1 + go.sum | 2 ++ main.go | 12 ++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml index bbbd9c0a5..1c9d68689 100644 --- a/.github/workflows/go-build.yaml +++ b/.github/workflows/go-build.yaml @@ -66,7 +66,7 @@ jobs: - name: Build warp-plus run: | - go build -v -o build_assets/ -trimpath -ldflags "-s -w -buildid=" . + go build -v -o build_assets/ -trimpath -ldflags "-s -w -buildid= -X main.version=${{ github.ref }}" . - name: Copy README.md & LICENSE run: | diff --git a/go.mod b/go.mod index 7ac9209f5..a5e551125 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/andybalholm/brotli v1.0.5 // indirect github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f // indirect github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61 // indirect + github.com/carlmjohnson/versioninfo v0.22.5 // indirect github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9 // indirect github.com/cognusion/go-cache-lru v0.0.0-20170419142635-f73e2280ecea // indirect github.com/dchest/siphash v1.2.3 // indirect diff --git a/go.sum b/go.sum index 49baf783f..a530a56a4 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/bepass-org/psiphon-tunnel-core v0.0.0-20240311155012-9c2e10df08e5 h1: github.com/bepass-org/psiphon-tunnel-core v0.0.0-20240311155012-9c2e10df08e5/go.mod h1:vA5iCui7nfavWyBN8MsLYZ5xpKItjrTvPC0SuMWz48Q= github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61 h1:BU+NxuoaYPIvvp8NNkNlLr8aA0utGyuunf4Q3LJ0bh0= github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU= +github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc= +github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9 h1:a1zrFsLFac2xoM6zG1u72DWJwZG3ayttYLfmLbxVETk= diff --git a/main.go b/main.go index 20c567cce..8a152969c 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "github.com/bepass-org/warp-plus/warp" "github.com/bepass-org/warp-plus/wiresocks" + "github.com/carlmjohnson/versioninfo" "github.com/peterbourgon/ff/v4" "github.com/peterbourgon/ff/v4/ffhelp" "github.com/peterbourgon/ff/v4/ffjson" @@ -59,6 +60,8 @@ var psiphonCountries = []string{ "US", } +var version string = "" + func main() { fs := ff.NewFlagSet(appName) var ( @@ -75,6 +78,7 @@ func main() { rtt = fs.DurationLong("rtt", 1000*time.Millisecond, "scanner rtt limit") cacheDir = fs.StringLong("cache-dir", "", "directory to store generated profiles") _ = fs.String('c', "config", "", "path to config file") + verFlag = fs.BoolLong("version", "displays version number") ) err := ff.Parse( @@ -92,6 +96,14 @@ func main() { os.Exit(1) } + if *verFlag { + if version == "" { + version = versioninfo.Short() + } + fmt.Fprintf(os.Stderr, "%s\n", version) + os.Exit(0) + } + l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) if *verbose {