From c375c7d922c997cb2f9c11ff2c73a2337eef90f4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 31 Mar 2021 19:02:40 +0200 Subject: [PATCH] cmd/soju: allow specifying -listen multiple times Closes: https://todo.sr.ht/~emersion/soju/67 --- cmd/soju/main.go | 21 ++++++++++++++++----- doc/soju.1.scd | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmd/soju/main.go b/cmd/soju/main.go index f62f36b..f7f8a42 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "flag" + "fmt" "log" "net" "net/http" @@ -24,10 +25,22 @@ import ( // TCP keep-alive interval for downstream TCP connections const downstreamKeepAlive = 1 * time.Hour +type stringSliceFlag []string + +func (v *stringSliceFlag) String() string { + return fmt.Sprint([]string(*v)) +} + +func (v *stringSliceFlag) Set(s string) error { + *v = append(*v, s) + return nil +} + func main() { - var listen, configPath string + var listen []string + var configPath string var debug bool - flag.StringVar(&listen, "listen", "", "listening address") + flag.Var((*stringSliceFlag)(&listen), "listen", "listening address") flag.StringVar(&configPath, "config", "", "path to configuration file") flag.BoolVar(&debug, "debug", false, "enable debug logging") flag.Parse() @@ -43,9 +56,7 @@ func main() { cfg = config.Defaults() } - if listen != "" { - cfg.Listen = append(cfg.Listen, listen) - } + cfg.Listen = append(cfg.Listen, listen...) if len(cfg.Listen) == 0 { cfg.Listen = []string{":6697"} } diff --git a/doc/soju.1.scd b/doc/soju.1.scd index 82bc2c9..1c09429 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -59,7 +59,7 @@ soju will reload the TLS certificate and key when it receives the HUP signal. passwords). *-listen* - Listening URI (default: ":6697"). + Listening URI (default: ":6697"). Can be specified multiple times. # CONFIG FILE