-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.rkt
62 lines (51 loc) · 1.99 KB
/
cli.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
#lang racket/base
(module+ main
(require
"./main.rkt"
"./threads.rkt"
racket/format
racket/string
racket/cmdline
racket/list
raco/command-name)
(define (format-paths paths)
(string-join
(map (lambda (p) (~a "--> " p)) paths)
(format "~n")))
(define method-string (make-parameter "robust"))
(define paths (command-line
#:program (short-program+command-name)
#:once-each
[("-m" "--method") user-method
("Use method: apathetic, intensive, robust (Default: robust)."
"Be warned that only 'robust' is cross-platform.")
(method-string user-method)]
#:args user-path-strings
(if (empty? user-path-strings)
(list (current-directory))
(map string->path user-path-strings))))
(define normalized-method-string
(case (method-string)
[("robust" "intensive" "apathetic") (method-string)]
[else "robust"]))
(define method (case normalized-method-string
[("robust") robust-watch]
[("intensive") intensive-watch]
[("apathetic") apathetic-watch]
[else robust-watch]))
(when (not (equal? normalized-method-string (method-string)))
(printf "Unrecognized method: ~a. Falling back to robust watch.~n" (method-string)))
(define does-not-exist (filter (λ (p) (not (path-on-disk? p))) paths))
(define exists (filter path-on-disk? paths))
(when (> (length does-not-exist) 0)
(printf "These paths do not exist on the system and will not be monitored:~n~a~n~n"
(format-paths does-not-exist)))
(if (> (length exists) 0)
(begin
(printf "Starting ~a watch over paths:~n~a~n~n"
normalized-method-string
(format-paths exists))
(with-handlers ([exn:break? (λ (e) (printf "~nStopping...~n"))])
(thread-wait (watch exists displayln displayln method))
(displayln "All watchers are done.")))
(displayln "Nothing to watch. Exiting.")))