most things work now?

main
m455 2018-04-13 01:02:48 -04:00
parent 6125f0e114
commit 711cd96ddb
4 changed files with 92 additions and 34 deletions

View File

@ -32,5 +32,10 @@
(equal? (vector-member initialize-command args) 0)) (equal? (vector-member initialize-command args) 0))
(initialize)] (initialize)]
[(and
(equal? args-length 1)
(member (vector-ref args 0) help-command))
(d-hash-ref messages 'show-help)]
[else [else
(d-hash-ref messages 'show-usage)]))) (d-hash-ref messages 'show-usage)])))

View File

@ -6,7 +6,14 @@
(define program-directory ".rodo/") (define program-directory ".rodo/")
(define program-path "~/") (define program-path "~/")
(define program-file "todo-list") (define program-file "todo-list")
(define path
(expand-user-path
(string-append
program-path
program-directory
program-file)))
(define remove-command "rm") (define remove-command "rm")
(define add-command "add") (define add-command "add")
(define list-command "ls") (define list-command "ls")
(define initialize-command "init") (define initialize-command "init")
(define help-command '("-h" "--help"))

View File

@ -6,6 +6,40 @@
(define messages (define messages
(hash (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 'show-usage
(string-append (string-append
"> For usage type " "> For usage type "

View File

@ -15,6 +15,14 @@
(define (d-vector-ref args key) (define (d-vector-ref args key)
(display (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) (define (make-numbered lst)
(map (map
string-append string-append
@ -28,13 +36,6 @@
(string-append ". " lst))) (string-append ". " lst)))
(define (show-list-from-file) (define (show-list-from-file)
(let
([path
(expand-user-path
(string-append
program-path
program-directory
program-file))])
(let (let
([todo-list ([todo-list
(file->lines path (file->lines path
@ -44,7 +45,7 @@
(string-join (string-join
(make-numbered (map (add-spaces) todo-list)) (make-numbered (map (add-spaces) todo-list))
"\n" "\n"
#:after-last "\n"))))) #:after-last "\n"))))
(define (show-list) (define (show-list)
(if (if
@ -56,19 +57,12 @@
(d-hash-ref messages 'file-not-found) (d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (d-hash-ref messages 'try-init))))
(define (add-item-to-file item) (define (add-item-to-file args)
(let ([item (string-append item "\n")]) (let ([args (string-append args "\n")])
(let (display-to-file args
([path
(expand-user-path
(string-append
program-path
program-directory
program-file))])
(display-to-file item
path path
#:mode 'text #:mode 'text
#:exists 'append)))) #:exists 'append)))
(define (add-item args) (define (add-item args)
(if (if
@ -84,16 +78,34 @@
(d-hash-ref messages 'file-not-found) (d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (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) (define (remove-item args)
(if (if
(and (and
(number? (string->number (vector-ref args 1)))
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(begin (remove-item-from-file (vector-ref args 1))
;; 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))
(begin (begin
(d-hash-ref messages 'file-not-found) (d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (d-hash-ref messages 'try-init))))