rodo/args.rkt

48 lines
1.4 KiB
Racket
Raw Normal View History

#lang racket/base
2019-11-13 21:00:45 +00:00
(require (prefix-in config: "config.rkt")
(prefix-in init: "init.rkt")
2019-11-15 12:37:40 +00:00
(prefix-in file: racket/file)
(prefix-in messages: "messages.rkt")
2019-11-13 18:59:02 +00:00
(prefix-in utils: "utils.rkt"))
(provide (all-defined-out))
(define (check-args args)
2020-02-02 04:18:43 +00:00
(let ([args-length (length args)]
2020-02-09 20:04:05 +00:00
[is-member? (lambda (command) (member (list-ref args 0) command))]
[args-second (string->number (list-ref args 1))])
2019-11-13 21:00:45 +00:00
(cond
[(equal? args-length 0)
2020-01-03 19:21:08 +00:00
(utils:display-messages '(show-usage))]
2019-11-13 21:00:45 +00:00
;; help-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 1)
2020-02-02 04:18:43 +00:00
(is-member? config:help-commands))
2020-01-03 19:21:08 +00:00
(utils:display-messages '(show-help))]
2019-11-13 21:00:45 +00:00
;; initialize-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 1)
2020-02-02 04:18:43 +00:00
(is-member? config:initialize-commands))
2019-11-22 18:35:25 +00:00
(init:check-initialize-conditions)]
2019-11-13 21:00:45 +00:00
;; add-command
2020-02-02 04:18:43 +00:00
[(and (>= args-length 2)
(is-member? config:add-commands))
2019-11-22 18:35:25 +00:00
(utils:check-add-conditions args)]
2019-11-13 21:00:45 +00:00
;; list-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 1)
2020-02-02 04:18:43 +00:00
(is-member? config:list-commands))
2019-11-22 18:35:25 +00:00
(utils:check-list-conditions)]
2019-11-13 21:00:45 +00:00
;; remove-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 2)
2020-02-02 04:18:43 +00:00
(is-member? config:remove-commands)
2020-02-09 20:04:05 +00:00
(real? args-second)
(or (positive? args-second)
(zero? args-second)))
2019-11-22 18:35:25 +00:00
(utils:check-remove-conditions args)]
2019-11-13 21:00:45 +00:00
2020-01-03 19:21:08 +00:00
[else (utils:display-messages '(show-usage))])))