From f2c20380a126a5b869094f8412f63812323ade0a Mon Sep 17 00:00:00 2001 From: octeep Date: Tue, 23 Aug 2022 21:43:30 +0800 Subject: [PATCH] add print version flag --- cmd/wireproxy/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/wireproxy/main.go b/cmd/wireproxy/main.go index 0f8bfda..0a86d5d 100644 --- a/cmd/wireproxy/main.go +++ b/cmd/wireproxy/main.go @@ -14,6 +14,8 @@ import ( // an argument to denote that this process was spawned by -d const daemonProcess = "daemon-process" +var version = "dev" + // attempts to pledge and panic if it fails // this does nothing on non-OpenBSD systems func pledgeOrPanic(promises string) { @@ -60,8 +62,9 @@ func main() { } parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying") - config := parser.String("c", "config", &argparse.Options{Required: true, Help: "Path of configuration file"}) + config := parser.String("c", "config", &argparse.Options{Help: "Path of configuration file"}) daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"}) + printVerison := parser.Flag("v", "version", &argparse.Options{Help: "Print version"}) configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."}) err := parser.Parse(args) @@ -70,6 +73,16 @@ func main() { return } + if *printVerison { + fmt.Printf("wireproxy, version %s\n", version) + return + } + + if *config == "" { + fmt.Println("configuration path is required") + return + } + if !*daemon { // remove proc and exec if they are not needed pledgeOrPanic("stdio rpath inet dns")