-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rkt
More file actions
50 lines (41 loc) · 1.61 KB
/
main.rkt
File metadata and controls
50 lines (41 loc) · 1.61 KB
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
#lang racket/base
(module+ main
(require racket/cmdline)
(require racket/runtime-path)
(require basedir)
(require "config.rkt")
(define-runtime-path prompter.rkt "prompter.rkt")
(define-runtime-path server.rkt "server.rkt")
(define-runtime-path client.rkt "client.rkt")
(define path-or-port (make-parameter #f))
(define daemon (make-parameter #f))
(define client (make-parameter #f))
(define command (make-parameter 'prompt))
(command-line
#:program "the-unicoder"
#:once-any
[("--path") path "path to unix socket"
(path-or-port path)]
[("--port") port "TCP port number (discouraged)"
(path-or-port (string->number port))]
#:once-any
[("--server") "run server"
(daemon #t)]
[("--client") "connect to server"
(client #t)]
#:once-each
[("--command") cmd "command to send to the server"
(command (string->symbol cmd))]
[("--delay") wait "delay between selecting a character and sending it (in milliseconds)"
(send-delay (/ (string->number wait) 1000))]
)
(when (and (not (path-or-port)) (or (daemon) (client)))
(path-or-port (writable-runtime-file "the-unicoder-socket"
#:program "the-unicoder")))
(cond [(daemon) (let ([serve (dynamic-require server.rkt 'serve)])
(serve (path-or-port)))]
[(client) (let ([send-command (dynamic-require client.rkt 'send-command)])
(send-command (path-or-port) (command)))]
[else (let ([prompt-once (dynamic-require prompter.rkt 'prompt-once)])
(prompt-once))])
)