add print version flag

This commit is contained in:
octeep 2022-08-23 21:43:30 +08:00 committed by octeep
parent 275c628654
commit f2c20380a1

View file

@ -14,6 +14,8 @@ import (
// an argument to denote that this process was spawned by -d // an argument to denote that this process was spawned by -d
const daemonProcess = "daemon-process" const daemonProcess = "daemon-process"
var version = "dev"
// attempts to pledge and panic if it fails // attempts to pledge and panic if it fails
// this does nothing on non-OpenBSD systems // this does nothing on non-OpenBSD systems
func pledgeOrPanic(promises string) { func pledgeOrPanic(promises string) {
@ -60,8 +62,9 @@ func main() {
} }
parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying") 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"}) 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."}) configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."})
err := parser.Parse(args) err := parser.Parse(args)
@ -70,6 +73,16 @@ func main() {
return return
} }
if *printVerison {
fmt.Printf("wireproxy, version %s\n", version)
return
}
if *config == "" {
fmt.Println("configuration path is required")
return
}
if !*daemon { if !*daemon {
// remove proc and exec if they are not needed // remove proc and exec if they are not needed
pledgeOrPanic("stdio rpath inet dns") pledgeOrPanic("stdio rpath inet dns")