made config a little more customizable

main
m455 2019-11-13 16:00:45 -05:00
parent 08e587c9a5
commit 1d601ee4c7
2 changed files with 56 additions and 39 deletions

View File

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

View File

@ -1,16 +1,34 @@
#lang racket/base #lang racket/base
(provide (all-defined-out)) (provide (all-defined-out))
(define list-file "todo.txt")
(define program-name "rodo") (define program-name "rodo")
(define program-directory (define program-directory
(path->string (path->string
(expand-user-path (expand-user-path
(string-append "~/." program-name "/")))) (string-append "~/." program-name "/"))))
(define list-file "todo.txt")
(define remove-command "rm")
(define add-command "add")
(define list-command "ls")
(define initialize-command "init")
(define help-command '("-h" "--help" "h" "help"))
(define path-to-list-file (define path-to-list-file
(string-append program-directory list-file)) (string-append program-directory list-file))
(define help-command '("-h"
"--help"
"h"
"help"))
(define initialize-command '("init"
"create"
"start"
"begin"))
(define add-command '("add"
"a"))
(define list-command '("ls"
"list"))
(define remove-command '("rm"
"remove"
"del"
"delete"))