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)
(real? (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)) (car (list:range (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-to-file)))))))
(util:remove-item args)]
;; init

View File

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

View File

@ -6,120 +6,120 @@
(define messages
(hash
'show-help (string-append
"Usage:"
"\n"
"rodo <command> [optional argument]\n"
"\n"
'show-help (string-append
"Usage:"
"\n"
"rodo <command> [optional argument]\n"
"\n"
config:initialize-command ":\n"
"Initialize a file in "
config:program-directory
config:program-file "\n"
config:initialize-command ":\n"
"Initialize a file in "
config:program-directory
config:program-file "\n"
"Example: "
"rodo init\n"
"\n"
"Example: "
"rodo init\n"
"\n"
config:list-command ":\n"
"Lists items on the list"
"\n"
"Example: "
"rodo ls\n"
"\n"
config:list-command ":\n"
"Lists items on the list"
"\n"
"Example: "
"rodo ls\n"
"\n"
config:add-command ":\n"
"Adds an item to the list"
"\n"
"Example: "
"rodo add bread\n"
"\n"
config:add-command ":\n"
"Adds an item to the list"
"\n"
"Example: "
"rodo add bread\n"
"\n"
"Note: For multi-word items you will need to\n"
"surround your item in double quotes as so:\n"
"rodo add \"go to the bank\"\n"
"\n"
"Note: For multi-word items you will need to\n"
"surround your item in double quotes as so:\n"
"rodo add \"go to the bank\"\n"
"\n"
config:remove-command ":\n"
"Removes an item from the list\n"
"Example: "
"rodo rm 1\n"
"\n"
config:remove-command ":\n"
"Removes an item from the list\n"
"Example: "
"rodo rm 1\n"
"\n"
"Note: You may have to use the ls command to see\n"
"which number corresponds to which item\n")
"Note: You may have to use the ls command to see\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
"> For usage type "
"`" config:program-name " -h`"
" or "
"`" config:program-name " --help`\n")
'show-usage (string-append
"> For usage type "
"`" config:program-name " -h`"
" or "
"`" config:program-name " --help`\n")
'creating (string-append
"> Creating "
config:program-file
" file in "
config:program-directory "\n")
'creating (string-append
"> Creating "
config:program-file
" file in "
config:program-directory "\n")
'creation-error (string-append
"> Error: Could not create "
config:program-file
" in "
config:program-directory
".\n"
"> This may be due to directory permissions\n")
'creation-error (string-append
"> Error: Could not create "
config:program-file
" in "
config:program-directory
".\n"
"> This may be due to directory permissions\n")
'file-already-exists (string-append
"> Error: "
config:program-name
" already exists in "
config:program-directory
config:program-file "\n")
'file-already-exists (string-append
"> Error: "
config:program-name
" already exists in "
config:program-directory
config:program-file "\n")
'successfully-created (string-append
"> "
config:program-directory
config:program-file
" has been successfully created\n")
'successfully-created (string-append
"> "
config:program-directory
config:program-file
" has been successfully created\n")
'file-not-found (string-append
"> Error: Could not find "
config:program-directory
config:program-file "\n")
'file-not-found (string-append
"> Error: Could not find "
config:program-directory
config:program-file "\n")
'init-y/n (string-append
"> A "
config:program-file
" file will be created in the directory "
config:program-directory "\n"
"> Are you sure you want to continue? [y/n]\n")
'init-y/n (string-append
"> A "
config:program-file
" file will be created in the directory "
config:program-directory "\n"
"> Are you sure you want to continue? [y/n]\n")
'try-init (string-append
"> Try typing "
"`" config:program-name " init` "
"to set it up\n")
'try-init (string-append
"> Try typing "
"`" config:program-name " init` "
"to set it up\n")
'terminating (string-append
"> Exiting "
config:program-name
"\n")
'terminating (string-append
"> Exiting "
config:program-name
"\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
(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))
(define (check-for-file)
(file-exists? config:path))
(file-exists? config:path-to-file))
(define (create-file)
(let ([opened-file
(open-output-file config:path
(open-output-file config:path-to-file
#:mode 'text
#:exists 'truncate)])
(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)
(directory-exists? (expand-user-path
(string-append
config:program-directory))))
(directory-exists? config:program-directory))
(define (create-directory)
(make-directory (expand-user-path
(string-append
config:program-directory)))
(make-directory config:program-directory)
(file-or-directory-permissions config:program-directory #o700))
(define (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
(define (file->string-list config:path-to-file)
(let ([todo-list (file:file->lines config:path-to-file
(define (file->string-list config:path-to-file-to-file)
(let ([todo-list (file:file->lines config:path-to-file-to-file
#:mode 'text
#:line-mode 'any)])
todo-list))
@ -69,7 +65,7 @@
(define (display-prettified-list)
(display
(string:string-join
(prefix-with-number (file->string-list config:path))
(prefix-with-number (file->string-list config:path-to-file))
"\n"
#:after-last "\n")))
@ -94,7 +90,7 @@
(if
;; If file exists, see if it's empty, if so
;; tell the user
(list-empty? config:path)
(list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list)
;; If file isn't empty, display a pretty list
(display-prettified-list))]
@ -105,10 +101,10 @@
(define (add-item-to-file args)
;; 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
(string:string-join new-list "\n")
config:path
config:path-to-file
#:mode 'text
#:exists 'truncate)
(display-item-added args)))
@ -117,25 +113,24 @@
(if (and
(check-for-directory)
(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))))
(begin
(display-hash-ref messages:messages 'file-not-found)
(display-hash-ref messages:messages 'try-init))))
(define (remove-item-from-file args)
(let* ([removed-item (get-removed-item config:path args)]
[new-list (remove removed-item (file->string-list config:path))])
(let* ([removed-item (get-removed-item config:path-to-file args)]
[new-list (remove removed-item (file->string-list config:path-to-file))])
(file:display-to-file
(string:string-join new-list "\n")
config:path
config:path-to-file
#:mode 'text
#:exists 'truncate)
(display-item-removed removed-item)))
(define (remove-item args)
(cond [(list-empty? config:path)
(cond [(list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list)]
[(and
(check-for-directory)