rodo/args.rkt

48 lines
1.8 KiB
Racket
Raw Normal View History

#lang racket/base
(require (prefix-in vector: racket/vector)
(prefix-in config: "config.rkt")
(prefix-in init: "init.rkt")
(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)
(let ([args-length (vector-length args)])
2019-11-04 02:32:11 +00:00
(cond [(equal? args-length 0)
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'show-usage)]
2019-11-04 02:32:11 +00:00
;; ls
[(and (equal? args-length 1)
(equal? (vector:vector-member config:list-command args) 0))
2019-11-13 18:59:02 +00:00
(utils:show-list-from-file config:path-to-list-file)]
2019-11-04 02:32:11 +00:00
;; add
[(and (or (equal? args-length 2) (>= args-length 2))
(equal? (vector-ref args 0) config:add-command))
2019-11-13 18:59:02 +00:00
(utils:add-item-to-list config:path-to-list-file args)]
2019-11-04 02:32:11 +00:00
;; rm
[(and (equal? args-length 2)
(equal? (vector-ref args 0) config:remove-command)
(real? (string->number (vector-ref args 1)))
(or (positive? (string->number (vector-ref args 1)))
(zero? (string->number (vector-ref args 1))))
;; Length subtract one because the numbering starts at zero
2019-11-13 18:59:02 +00:00
(not (> (string->number (vector-ref args 1)) (sub1 (length (utils:file->string-list config:path-to-list-file))))))
(utils:remove-item-from-list config:path-to-list-file args)]
2019-11-04 02:32:11 +00:00
;; init
[(and (equal? args-length 1)
(equal? (vector:vector-member config:initialize-command args) 0))
(init:initialize)]
;; help
[(and (equal? args-length 1)
(member (vector-ref args 0) config:help-command))
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'show-help)]
2019-11-04 02:32:11 +00:00
[else
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'show-usage)])))