From 77bd80fbbd4b874770da1f9060f7246ea6b40890 Mon Sep 17 00:00:00 2001 From: octeep Date: Wed, 30 Mar 2022 18:27:52 +0100 Subject: [PATCH] add configtest flag --- README.md | 9 ++++++--- cmd/wireproxy/main.go | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index deef06e..12583f6 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,17 @@ anything. ``` usage: wireproxy [-h|--help] -c|--config "" [-d|--daemon] + [-n|--configtest] Userspace wireguard client for proxying Arguments: - -h --help Print help information - -c --config Path of configuration file - -d --daemon Make wireproxy run in background + -h --help Print help information + -c --config Path of configuration file + -d --daemon Make wireproxy run in background + -n --configtest Configtest mode. Only check the configuration file for + validity. ``` # Sample config file diff --git a/cmd/wireproxy/main.go b/cmd/wireproxy/main.go index d56d33f..c668e9d 100644 --- a/cmd/wireproxy/main.go +++ b/cmd/wireproxy/main.go @@ -13,7 +13,7 @@ import ( const daemonProcess = "daemon-process" func main() { - isDaemonProcess := os.Args[1] == daemonProcess + isDaemonProcess := len(os.Args) > 1 && os.Args[1] == daemonProcess args := os.Args if isDaemonProcess { args = []string{args[0]} @@ -24,6 +24,7 @@ func main() { config := parser.String("c", "config", &argparse.Options{Required: true, Help: "Path of configuration file"}) daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"}) + configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."}) err := parser.Parse(args) if err != nil { @@ -31,6 +32,16 @@ func main() { return } + conf, err := wireproxy.ParseConfig(*config) + if err != nil { + log.Panic(err) + } + + if *configTest { + fmt.Println("Config OK") + return + } + if isDaemonProcess { os.Stdout, _ = os.Open(os.DevNull) os.Stderr, _ = os.Open(os.DevNull) @@ -53,11 +64,6 @@ func main() { return } - conf, err := wireproxy.ParseConfig(*config) - if err != nil { - log.Panic(err) - } - tnet, err := wireproxy.StartWireguard(conf.Device) if err != nil { log.Panic(err)