Simplified command line parsing and pattern matching by using a match expander
parent
93cccaa9fd
commit
bad36d5229
38
src/rodo.rkt
38
src/rodo.rkt
|
@ -278,35 +278,19 @@
|
||||||
(define (args-ref number)
|
(define (args-ref number)
|
||||||
(vector-ref vectorof-args number))
|
(vector-ref vectorof-args number))
|
||||||
(match vectorof-args
|
(match vectorof-args
|
||||||
[(vector a)
|
[(or (vector (== help-command-1))
|
||||||
(cond
|
(vector (== help-command-2))
|
||||||
[(ormap (lambda (x) (equal? a x))
|
(vector (== help-command-3))) (help)]
|
||||||
(list help-command-1
|
[(vector (== ls-command)) (ls)]
|
||||||
help-command-2
|
[(vector (== init-command)) (init)]
|
||||||
help-command-3))
|
[(vector (== add-command) _) (add (args-ref 1))]
|
||||||
(help)]
|
[(vector (== rm-command) _) (rm (args-ref 1))]
|
||||||
|
|
||||||
[(equal? a ls-command)
|
|
||||||
(ls)]
|
|
||||||
|
|
||||||
[(equal? a init-command)
|
|
||||||
(init)]
|
|
||||||
|
|
||||||
[else (displayln-messages-ref 'error-incorrect-usage)])]
|
|
||||||
|
|
||||||
[(vector a _)
|
|
||||||
(cond
|
|
||||||
[(equal? a add-command)
|
|
||||||
(add (args-ref 1))]
|
|
||||||
|
|
||||||
[(equal? a rm-command)
|
|
||||||
(rm (args-ref 1))]
|
|
||||||
|
|
||||||
[else (displayln-messages-ref 'error-incorrect-usage)])]
|
|
||||||
|
|
||||||
[(vector _ _ _ ...)
|
[(vector _ _ _ ...)
|
||||||
(displayln-messages-ref 'error-too-many-arguments)]
|
(displayln-messages-ref 'error-too-many-arguments)]
|
||||||
|
[(vector _ _)
|
||||||
|
(displayln-messages-ref 'error-incorrect-usage)]
|
||||||
|
[(vector _)
|
||||||
|
(displayln-messages-ref 'error-incorrect-usage)]
|
||||||
[_ (ls)]))
|
[_ (ls)]))
|
||||||
|
|
||||||
(define (main vectorof-args)
|
(define (main vectorof-args)
|
||||||
|
|
Loading…
Reference in New Issue