From 711cd96ddbeeab362a79613daa62e2556db7df3e Mon Sep 17 00:00:00 2001 From: m455 Date: Fri, 13 Apr 2018 01:02:48 -0400 Subject: [PATCH] most things work now? --- args.rkt | 5 ++++ config.rkt | 7 +++++ messages.rkt | 34 ++++++++++++++++++++++ util.rkt | 80 ++++++++++++++++++++++++++++++---------------------- 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/args.rkt b/args.rkt index 395c8ac..d7d555d 100644 --- a/args.rkt +++ b/args.rkt @@ -32,5 +32,10 @@ (equal? (vector-member initialize-command args) 0)) (initialize)] + [(and + (equal? args-length 1) + (member (vector-ref args 0) help-command)) + (d-hash-ref messages 'show-help)] + [else (d-hash-ref messages 'show-usage)]))) diff --git a/config.rkt b/config.rkt index c0b963a..ac5da0f 100644 --- a/config.rkt +++ b/config.rkt @@ -6,7 +6,14 @@ (define program-directory ".rodo/") (define program-path "~/") (define program-file "todo-list") +(define path + (expand-user-path + (string-append + program-path + program-directory + program-file))) (define remove-command "rm") (define add-command "add") (define list-command "ls") (define initialize-command "init") +(define help-command '("-h" "--help")) diff --git a/messages.rkt b/messages.rkt index fcb9875..2198be7 100644 --- a/messages.rkt +++ b/messages.rkt @@ -6,6 +6,40 @@ (define messages (hash + 'show-help + (string-append + "* " initialize-command ": " + "initialize a file in " + program-path + program-directory + program-file + "\n" + "\x09Example: " + "rodo init\n\n" + + "* " list-command ": " + "lists items on the list" + "\n" + "\x09Example: " + "rodo rm 1\n\n" + + + "* " add-command ": " + "adds an item to the list" + "\n" + "\x09Note: For multi-word items you will need to\n" + "\x09surround your item in double quotes as so:\n" + "\x09rodo add \"go to the bank\"\n" + "\x09Example: " + "rodo add bread\n\n" + + "* " remove-command ": " + "removes an item from the list\n" + "\x09Note: You may have to run `rodo ls` to see which\n" + "\x09number corresponds to which item to remove it.\n" + "\x09Example: " + "rodo rm 1\n") + 'show-usage (string-append "> For usage type " diff --git a/util.rkt b/util.rkt index 6b5024e..ec031f9 100644 --- a/util.rkt +++ b/util.rkt @@ -15,6 +15,14 @@ (define (d-vector-ref args key) (display (vector-ref args key))) +(define (quote-item-in-list lst args) + (display + (string-append + "\"" + (list-ref lst + (string->number args)) + "\""))) + (define (make-numbered lst) (map string-append @@ -29,22 +37,15 @@ (define (show-list-from-file) (let - ([path - (expand-user-path - (string-append - program-path - program-directory - program-file))]) - (let - ([todo-list - (file->lines path - #:mode 'text - #:line-mode 'linefeed)]) - (display - (string-join - (make-numbered (map (add-spaces) todo-list)) - "\n" - #:after-last "\n"))))) + ([todo-list + (file->lines path + #:mode 'text + #:line-mode 'linefeed)]) + (display + (string-join + (make-numbered (map (add-spaces) todo-list)) + "\n" + #:after-last "\n")))) (define (show-list) (if @@ -56,19 +57,12 @@ (d-hash-ref messages 'file-not-found) (d-hash-ref messages 'try-init)))) -(define (add-item-to-file item) - (let ([item (string-append item "\n")]) - (let - ([path - (expand-user-path - (string-append - program-path - program-directory - program-file))]) - (display-to-file item - path - #:mode 'text - #:exists 'append)))) +(define (add-item-to-file args) + (let ([args (string-append args "\n")]) + (display-to-file args + path + #:mode 'text + #:exists 'append))) (define (add-item args) (if @@ -84,16 +78,34 @@ (d-hash-ref messages 'file-not-found) (d-hash-ref messages 'try-init)))) +(define (remove-item-from-file args) + (let ([todo-list + (file->lines path + #:mode 'text + #:line-mode 'linefeed)]) + (d-hash-ref messages 'item-removed-prefix) + (quote-item-in-list todo-list args) + (d-hash-ref messages 'item-removed-suffix) + (let ([new-list + (remove + (list-ref + todo-list + (string->number + args)) + todo-list)]) + (display-to-file + (string-append (string-join new-list "\n") "\n") + path + #:mode 'text + #:exists 'replace)))) + (define (remove-item args) (if (and + (number? (string->number (vector-ref args 1))) (check-for-folder) (check-for-file)) - (begin - ;; TODO (remove-item-from-file (vector-ref args 1)) - (d-hash-ref messages 'item-removed-prefix) - (d-vector-ref args 1) - (d-hash-ref messages 'item-removed-suffix)) + (remove-item-from-file (vector-ref args 1)) (begin (d-hash-ref messages 'file-not-found) (d-hash-ref messages 'try-init))))