diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-04 16:26:24 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-04 16:26:38 +0200 |
commit | d78298ddcdf6a4f83a43ccc8b852fe2729ca547b (patch) | |
tree | 77d4930cf0be91e78b55edc9236b3e8db57c77a9 /module/entry-points | |
parent | Allow program to throw 'return to exit gracefully. (diff) | |
download | calp-d78298ddcdf6a4f83a43ccc8b852fe2729ca547b.tar.gz calp-d78298ddcdf6a4f83a43ccc8b852fe2729ca547b.tar.xz |
Add --help to server.
Diffstat (limited to 'module/entry-points')
-rw-r--r-- | module/entry-points/server.scm | 24 |
1 files 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. |