removed several string-appends that were no longer needed

main
m455 2019-03-12 22:41:18 -04:00
parent 7ebf92132e
commit fb643f7398
4 changed files with 109 additions and 117 deletions

View File

@ -33,8 +33,8 @@
(equal? (vector:vector-member config:remove-command args) 0) (equal? (vector:vector-member config:remove-command args) 0)
(real? (string->number (vector-ref args 1))) (real? (string->number (vector-ref args 1)))
(positive? (string->number (vector-ref args 1))) (positive? (string->number (vector-ref args 1)))
(not (> (string->number (vector-ref args 1)) (length (util:file->string-list config:path)))) (not (> (string->number (vector-ref args 1)) (length (util:file->string-list config:path-to-file))))
(not (< (string->number (vector-ref args 1)) (car (list:range (length (util:file->string-list config:path))))))) (not (< (string->number (vector-ref args 1)) (car (list:range (length (util:file->string-list config:path-to-file)))))))
(util:remove-item args)] (util:remove-item args)]
;; init ;; init

View File

@ -9,7 +9,4 @@
(define list-command "ls") (define list-command "ls")
(define initialize-command "init") (define initialize-command "init")
(define help-command '("-h" "--help")) (define help-command '("-h" "--help"))
(define path (define path-to-file (string-append program-directory program-file))
(string-append
program-directory
program-file))

View File

@ -6,120 +6,120 @@
(define messages (define messages
(hash (hash
'show-help (string-append 'show-help (string-append
"Usage:" "Usage:"
"\n" "\n"
"rodo <command> [optional argument]\n" "rodo <command> [optional argument]\n"
"\n" "\n"
config:initialize-command ":\n" config:initialize-command ":\n"
"Initialize a file in " "Initialize a file in "
config:program-directory config:program-directory
config:program-file "\n" config:program-file "\n"
"Example: " "Example: "
"rodo init\n" "rodo init\n"
"\n" "\n"
config:list-command ":\n" config:list-command ":\n"
"Lists items on the list" "Lists items on the list"
"\n" "\n"
"Example: " "Example: "
"rodo ls\n" "rodo ls\n"
"\n" "\n"
config:add-command ":\n" config:add-command ":\n"
"Adds an item to the list" "Adds an item to the list"
"\n" "\n"
"Example: " "Example: "
"rodo add bread\n" "rodo add bread\n"
"\n" "\n"
"Note: For multi-word items you will need to\n" "Note: For multi-word items you will need to\n"
"surround your item in double quotes as so:\n" "surround your item in double quotes as so:\n"
"rodo add \"go to the bank\"\n" "rodo add \"go to the bank\"\n"
"\n" "\n"
config:remove-command ":\n" config:remove-command ":\n"
"Removes an item from the list\n" "Removes an item from the list\n"
"Example: " "Example: "
"rodo rm 1\n" "rodo rm 1\n"
"\n" "\n"
"Note: You may have to use the ls command to see\n" "Note: You may have to use the ls command to see\n"
"which number corresponds to which item\n") "which number corresponds to which item\n")
'empty-todo-list "> There is nothing in your list \n" 'empty-todo-list "> There is nothing in your list \n"
'show-usage (string-append 'show-usage (string-append
"> For usage type " "> For usage type "
"`" config:program-name " -h`" "`" config:program-name " -h`"
" or " " or "
"`" config:program-name " --help`\n") "`" config:program-name " --help`\n")
'creating (string-append 'creating (string-append
"> Creating " "> Creating "
config:program-file config:program-file
" file in " " file in "
config:program-directory "\n") config:program-directory "\n")
'creation-error (string-append 'creation-error (string-append
"> Error: Could not create " "> Error: Could not create "
config:program-file config:program-file
" in " " in "
config:program-directory config:program-directory
".\n" ".\n"
"> This may be due to directory permissions\n") "> This may be due to directory permissions\n")
'file-already-exists (string-append 'file-already-exists (string-append
"> Error: " "> Error: "
config:program-name config:program-name
" already exists in " " already exists in "
config:program-directory config:program-directory
config:program-file "\n") config:program-file "\n")
'successfully-created (string-append 'successfully-created (string-append
"> " "> "
config:program-directory config:program-directory
config:program-file config:program-file
" has been successfully created\n") " has been successfully created\n")
'file-not-found (string-append 'file-not-found (string-append
"> Error: Could not find " "> Error: Could not find "
config:program-directory config:program-directory
config:program-file "\n") config:program-file "\n")
'init-y/n (string-append 'init-y/n (string-append
"> A " "> A "
config:program-file config:program-file
" file will be created in the directory " " file will be created in the directory "
config:program-directory "\n" config:program-directory "\n"
"> Are you sure you want to continue? [y/n]\n") "> Are you sure you want to continue? [y/n]\n")
'try-init (string-append 'try-init (string-append
"> Try typing " "> Try typing "
"`" config:program-name " init` " "`" config:program-name " init` "
"to set it up\n") "to set it up\n")
'terminating (string-append 'terminating (string-append
"> Exiting " "> Exiting "
config:program-name config:program-name
"\n") "\n")
'choose-y/n "> Error: Please choose y or n\n" 'choose-y/n "> Error: Please choose y or n\n"
'not-in-list "> Error: Item does not exist\n" 'not-in-list "> Error: Item does not exist\n"
'item-added-prefix "> Added " 'item-added-prefix "> Added "
'item-added-suffix " to list\n" 'item-added-suffix " to list\n"
'item-removed-prefix "> Removed " 'item-removed-prefix "> Removed "
'item-removed-suffix " from list\n")) 'item-removed-suffix " from list\n"))
(define y/n (define y/n
(hash (hash
'yes '("yes" "Yes" "y" "Y") 'yes '("yes" "Yes" "y" "Y")
'no '("no" "No" "n" "N"))) 'no '("no" "No" "n" "N")))

View File

@ -9,33 +9,29 @@
(provide (all-defined-out)) (provide (all-defined-out))
(define (check-for-file) (define (check-for-file)
(file-exists? config:path)) (file-exists? config:path-to-file))
(define (create-file) (define (create-file)
(let ([opened-file (let ([opened-file
(open-output-file config:path (open-output-file config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate)]) #:exists 'truncate)])
(close-output-port opened-file)) (close-output-port opened-file))
(file-or-directory-permissions config:path #o600)) (file-or-directory-permissions config:path-to-file #o600))
(define (check-for-directory) (define (check-for-directory)
(directory-exists? (expand-user-path (directory-exists? config:program-directory))
(string-append
config:program-directory))))
(define (create-directory) (define (create-directory)
(make-directory (expand-user-path (make-directory config:program-directory)
(string-append
config:program-directory)))
(file-or-directory-permissions config:program-directory #o700)) (file-or-directory-permissions config:program-directory #o700))
(define (display-hash-ref hash-list key) (define (display-hash-ref hash-list key)
(display (hash-ref hash-list key))) (display (hash-ref hash-list key)))
;; Just so I don't have to keep typing "#:mode...#:line-mode..." every time ;; Just so I don't have to keep typing "#:mode...#:line-mode..." every time
(define (file->string-list config:path-to-file) (define (file->string-list config:path-to-file-to-file)
(let ([todo-list (file:file->lines config:path-to-file (let ([todo-list (file:file->lines config:path-to-file-to-file
#:mode 'text #:mode 'text
#:line-mode 'any)]) #:line-mode 'any)])
todo-list)) todo-list))
@ -69,7 +65,7 @@
(define (display-prettified-list) (define (display-prettified-list)
(display (display
(string:string-join (string:string-join
(prefix-with-number (file->string-list config:path)) (prefix-with-number (file->string-list config:path-to-file))
"\n" "\n"
#:after-last "\n"))) #:after-last "\n")))
@ -94,7 +90,7 @@
(if (if
;; If file exists, see if it's empty, if so ;; If file exists, see if it's empty, if so
;; tell the user ;; tell the user
(list-empty? config:path) (list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list) (display-hash-ref messages:messages 'empty-todo-list)
;; If file isn't empty, display a pretty list ;; If file isn't empty, display a pretty list
(display-prettified-list))] (display-prettified-list))]
@ -105,10 +101,10 @@
(define (add-item-to-file args) (define (add-item-to-file args)
;; Add item to end of list and write to file ;; Add item to end of list and write to file
(let ([new-list (append-to-end args config:path)]) (let ([new-list (append-to-end args config:path-to-file)])
(file:display-to-file (file:display-to-file
(string:string-join new-list "\n") (string:string-join new-list "\n")
config:path config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate) #:exists 'truncate)
(display-item-added args))) (display-item-added args)))
@ -117,25 +113,24 @@
(if (and (if (and
(check-for-directory) (check-for-directory)
(check-for-file)) (check-for-file))
;; The cdr here removes the command string "add" from being added to the file ;; The cdr here prevents the command line argument "add" from being added to the file
(add-item-to-file (string:string-join (cdr (vector->list args)))) (add-item-to-file (string:string-join (cdr (vector->list args))))
(begin (begin
(display-hash-ref messages:messages 'file-not-found) (display-hash-ref messages:messages 'file-not-found)
(display-hash-ref messages:messages 'try-init)))) (display-hash-ref messages:messages 'try-init))))
(define (remove-item-from-file args) (define (remove-item-from-file args)
(let* ([removed-item (get-removed-item config:path args)] (let* ([removed-item (get-removed-item config:path-to-file args)]
[new-list (remove removed-item (file->string-list config:path))]) [new-list (remove removed-item (file->string-list config:path-to-file))])
(file:display-to-file (file:display-to-file
(string:string-join new-list "\n") (string:string-join new-list "\n")
config:path config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate) #:exists 'truncate)
(display-item-removed removed-item))) (display-item-removed removed-item)))
(define (remove-item args) (define (remove-item args)
(cond [(list-empty? config:path) (cond [(list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list)] (display-hash-ref messages:messages 'empty-todo-list)]
[(and [(and
(check-for-directory) (check-for-directory)