rodo/args.rkt

46 lines
1.5 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)
2019-11-15 12:37:40 +00:00
(let ([args-length (length args)])
2019-11-13 21:00:45 +00:00
(cond
[(equal? args-length 0)
(utils:display-hash-ref messages:messages 'show-usage)]
;; help-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 1)
2019-11-22 18:35:25 +00:00
(member (list-ref args 0) config:help-commands))
2019-11-13 21:00:45 +00:00
(utils:display-hash-ref messages:messages 'show-help)]
;; initialize-command
2019-11-13 21:00:45 +00:00
[(and (equal? args-length 1)
2019-11-22 18:35:25 +00:00
(member (list-ref args 0) config:initialize-commands))
(init:check-initialize-conditions)]
2019-11-13 21:00:45 +00:00
;; add-command
2019-11-13 21:00:45 +00:00
[(and (or (equal? args-length 2) (>= args-length 2))
2019-11-22 18:35:25 +00:00
(member (list-ref args 0) config:add-commands))
(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)
2019-11-22 18:35:25 +00:00
(member (list-ref args 0) config:list-commands))
(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)
2019-11-22 18:35:25 +00:00
(member (list-ref args 0) config:remove-commands)
2019-11-15 12:37:40 +00:00
(real? (string->number (list-ref args 1)))
(or (positive? (string->number (list-ref args 1)))
(zero? (string->number (list-ref args 1)))))
2019-11-22 18:35:25 +00:00
(utils:check-remove-conditions args)]
2019-11-13 21:00:45 +00:00
[else (utils:display-hash-ref messages:messages 'show-usage)])))