rodo/args.rkt

52 lines
1.7 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)]
[is-member? (lambda (command)
(member (list-ref args 0) command))])
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)
;; possibly replace this with something that checks
;; the length, the creates a range with that, starting
;; from zero, and checks to see if the user input
;; is a member of that list
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
2020-01-03 19:21:08 +00:00
[else (utils:display-messages '(show-usage))])))