-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.rkt
73 lines (62 loc) · 1.86 KB
/
command.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#lang racket/base
(require (only-in racket/match
match)
#;raco/command-name
(only-in web-server/servlet-env
serve/servlet)
(prefix-in first:
(only-in (file "first.rkt")
start))
(prefix-in second:
(only-in (file "second.rkt")
start))
(prefix-in third:
(only-in (file "third.rkt")
start))
(prefix-in fourth:
(only-in (file "fourth.rkt")
start)))
(define opt-port 31872)
(module+ raco
(define command-name (with-handlers ([exn:fail? (λ _ #f)])
(vector-ref (current-command-line-arguments) 0)))
(dispatch command-name))
(define (dispatch command-name)
(match command-name
[(or #f "help")
(handle-help)]
["first"
(handle-first)]
["second"
(handle-second)]
["third"
(handle-third)]
["fourth"
(handle-fourth)]
[else
(handle-unknown command-name)]))
(define (handle-unknown command)
(displayln (format "Unknown command `~a`." command))
(handle-help))
(define (run-server start)
(serve/servlet start
#:command-line? #f
#:stateless? #t
#:launch-browser? #f
#:servlet-regexp #rx".*"
#:port opt-port))
(define (handle-first)
(run-server first:start))
(define (handle-second)
(run-server second:start))
(define (handle-third)
(run-server third:start))
(define (handle-fourth)
(run-server fourth:start))
(define (handle-help)
(displayln "Available commands:
help show this message
first launch the first server
second launch the second server
third launch the third server
fourth launch the fourth server"))