-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rkt
68 lines (58 loc) · 1.93 KB
/
main.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
#lang racket/base
;; Front-end for `raco ipoe`
(require
racket/match
(prefix-in cmd: ipoe/private/command)
(only-in racket/string string-suffix?)
)
;; =============================================================================
(define print-help
(let* ([pad-width (for/fold ([acc 0]) ([d (in-list cmd:command-descriptions)])
(max acc (string-length (car d))))]
[add-padding (λ (sym) (format " ~a~a " sym (make-string (- pad-width (string-length sym)) #\space)))])
(λ ()
(printf "Usage: raco ipoe <command> <arg> ...~n~n")
(printf "Commands:~n")
(for ([d (in-list cmd:command-descriptions)])
(printf "~a~a~n" (add-padding (car d)) (cdr d)))
(void))))
(define (print-unknown k)
(printf "Unrecognized command '~a'. Use `raco ipoe --help` to see a list of available commands.\n" k))
;; =============================================================================
(module+ main
(require racket/cmdline)
(command-line
#:program "ipoe"
#:args ARG*
(if (null? ARG*)
(print-help)
(match (string->symbol (car ARG*))
;; scrape? get-rhymes? (full report?, repl?)
;; share?
;; edit? audit? or build this into NEW
['check
(cmd:check (cdr ARG*))]
[rkt
#:when (string-suffix? (car ARG*) ".rkt")
;; Shortcut for checking, instead of 'racket FILE.rkt'
(cmd:check ARG*)]
[(or 'db 'dbshell)
(cmd:dbshell (cdr ARG*))]
['help
(print-help)]
['init
(cmd:init (cdr ARG*))]
[(or 'new 'add)
(cmd:new (cdr ARG*))]
['remove
(cmd:remove (cdr ARG*))]
[(or 'show 'list)
(cmd:show (cdr ARG*))]
['update
(cmd:update (cdr ARG*))]
[k
(print-unknown k)]))))
;; =============================================================================
(module+ test
(require rackunit)
)