From d78298ddcdf6a4f83a43ccc8b852fe2729ca547b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 4 May 2020 16:26:24 +0200 Subject: Add --help to server. --- module/entry-points/server.scm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/module/entry-points/server.scm b/module/entry-points/server.scm index 324cac88..f1a5466d 100644 --- a/module/entry-points/server.scm +++ b/module/entry-points/server.scm @@ -2,6 +2,7 @@ :use-module (util) :use-module (util app) :use-module (util config) + :use-module (util options) :use-module (srfi srfi-1) @@ -162,15 +163,24 @@ (1+ state))))) (define options - '((port (value #t) (single-char #\p)) - (addr (value #t)) + '((port (value #t) (single-char #\p) + (description (*TOP* "Bind to TCP port, defaults to " (i 8080) "."))) + (addr (value #t) + (description (*TOP* "Address to use, defaults to " (i "0.0.0.0") + " for IPv4, and " (i "::") " for IPv6.")) + ) ;; TODO numbers as single-char seems to not work. - (six (single-char #\6)) - (four (single-char #\4)))) + (six (single-char #\6) + (description "Use IPv6.")) + (four (single-char #\4) + (description "Use IPv4.")) + (help (single-char #\h) + (description "Print this help.")))) + (define-public (main args) - (define opts (getopt-long args options)) + (define opts (getopt-long args (getopt-opt options))) (define port (string->number (option-ref opts 'port "8080"))) (define addr (option-ref opts 'addr #f)) (define family @@ -180,6 +190,10 @@ [(and addr (string-contains addr ".")) AF_INET] [else AF_INET6])) + (when (option-ref opts 'help #f) + (print-arg-help options) + (throw 'return)) + ;; update address if it was left blank. A bit clumsy since ;; @var{addr} & @var{family} depend on each other. ;; placed after load-calendars to keep Guile 2.2 compability. -- cgit v1.2.3