From 1d601ee4c7bbf7c1142d7309690cb34a7f20a1c8 Mon Sep 17 00:00:00 2001 From: m455 Date: Wed, 13 Nov 2019 16:00:45 -0500 Subject: [PATCH] made config a little more customizable --- args.rkt | 61 +++++++++++++++++++++++++++--------------------------- config.rkt | 34 +++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/args.rkt b/args.rkt index 6512c2e..ebbae0f 100644 --- a/args.rkt +++ b/args.rkt @@ -1,7 +1,6 @@ #lang racket/base -(require (prefix-in vector: racket/vector) - (prefix-in config: "config.rkt") +(require (prefix-in config: "config.rkt") (prefix-in init: "init.rkt") (prefix-in messages: "messages.rkt") (prefix-in utils: "utils.rkt")) @@ -10,38 +9,38 @@ (define (check-args args) (let ([args-length (vector-length args)]) - (cond [(equal? args-length 0) - (utils:display-hash-ref messages:messages 'show-usage)] + (cond + [(equal? args-length 0) + (utils:display-hash-ref messages:messages 'show-usage)] - ;; ls - [(and (equal? args-length 1) - (equal? (vector:vector-member config:list-command args) 0)) - (utils:show-list-from-file config:path-to-list-file)] + ;; help + [(and (equal? args-length 1) + (member (vector-ref args 0) config:help-command)) + (utils:display-hash-ref messages:messages 'show-help)] - ;; add - [(and (or (equal? args-length 2) (>= args-length 2)) - (equal? (vector-ref args 0) config:add-command)) - (utils:add-item-to-list config:path-to-list-file args)] + ;; init + [(and (equal? args-length 1) + (member (vector-ref args 0) config:initialize-command)) + (init:initialize)] - ;; 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 - (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)] + ;; add + [(and (or (equal? args-length 2) (>= args-length 2)) + (member (vector-ref args 0) config:add-command)) + (utils:add-item-to-list config:path-to-list-file args)] - ;; init - [(and (equal? args-length 1) - (equal? (vector:vector-member config:initialize-command args) 0)) - (init:initialize)] + ;; ls + [(and (equal? args-length 1) + (member (vector-ref args 0) config:list-command)) + (utils:show-list-from-file config:path-to-list-file)] - ;; help - [(and (equal? args-length 1) - (member (vector-ref args 0) config:help-command)) - (utils:display-hash-ref messages:messages 'show-help)] + ;; rm + [(and (equal? args-length 2) + (member (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 + (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 - (utils:display-hash-ref messages:messages 'show-usage)]))) + [else (utils:display-hash-ref messages:messages 'show-usage)]))) diff --git a/config.rkt b/config.rkt index fa5b040..284166a 100644 --- a/config.rkt +++ b/config.rkt @@ -1,16 +1,34 @@ #lang racket/base (provide (all-defined-out)) +(define list-file "todo.txt") (define program-name "rodo") + (define program-directory (path->string - (expand-user-path - (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")) + (expand-user-path + (string-append "~/." program-name "/")))) + (define path-to-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"))