finished writing the repair procedures

cleanup
m455 2020-06-14 16:39:48 -04:00
parent b5d93d4614
commit b3824baba4
1 changed files with 33 additions and 18 deletions

View File

@ -5,10 +5,13 @@
;; ------------------------------------------------
(define messages
(hash
'not-found "'~a' wasn't found"
'repair-prompt "You will need it to use nicethings\nDo you want to create it? [y/n]"
'fake-file-found "The file '~a' was found. Please move this file somewhere else to use nicethings"
'not-a-command "Error: '~a' is not a command"))
'not-found "'~a' wasn't found."
'repair-prompt "You will need it to use nicethings.\nDo you want to create it? [y/n]\n> "
'fake-file-found "The directory '~a' was found.\nPlease move this file somewhere else before using nicethings."
'not-a-command "Error: '~a' is not a command."
'cancel-creation "Cancelled nicethings file creation."
'file-created "'~a' was successfully created."
'not-an-option "Error: '~a' is not an option."))
;; ------------------------------------------------
;; helpers
@ -25,22 +28,34 @@
;; ------------------------------------------------
;; repair
;; ------------------------------------------------
(define (repair/cancel)
(displayln (messages-ref 'cancel-creation))
(exit))
;; Check for a "fake" '.nicethings' file,
;; which is a directory named '.nicethings'
(define (repair/start dot-nicethings-path)
(if (directory-exists? dot-nicethings-path)
(displayln-format (messages-ref 'fake-file-found) dot-nicethings-path)
(begin (close-output-port (open-output-file dot-nicethings-path))
(displayln-format (messages-ref 'file-created) dot-nicethings-path))))
(define (repair/prompt dot-nicethings-path)
(display (messages-ref 'repair-prompt))
(let ([user-input (read-line)])
(case (string->symbol user-input)
['y (repair/start dot-nicethings-path)]
['n (repair/cancel)]
[else (displayln-format (messages-ref 'not-an-option) user-input)])))
(define (repair)
(let* ([dot-nicethings-string ".nicethings"]
[home-directory (find-system-path 'home-dir)]
[listof-home-contents (directory-list home-directory)]
[dot-nicethings-path (build-path home-directory dot-nicethings-string)])
(when (not (directory-exists? dot-nicethings-path))
(when (not (file-exists? dot-nicethings-path))
(displayln-format (messages-ref 'not-found) dot-nicethings-path)
(displayln (messages-ref 'repair-prompt))
;; Check for a "fake" '.nicethings' directory,
;; which is a file named '.nicethings'
(if (file-exists? dot-nicethings-path)
(displayln-format (messages-ref 'fake-file-found) dot-nicethings-path)
(make-directory dot-nicethings-path))
;; TODO: check if file exists. basically the opposite of above
;; and then create the file
)))
(repair/prompt dot-nicethings-path))))
;; ------------------------------------------------
;; random message
@ -58,10 +73,10 @@
" town nicethings [<command>] [<args>]"
""
"Commands:"
" No command - Print a random message"
" add - Add a message to the list of messages"
" ls - Print a numbered list of the messages you have added"
" rm - Remove a message from the list of messages"
" No command - Print a random message."
" add - Add a message to the list of messages."
" ls - Print a numbered list of the messages you have added."
" rm - Remove a message from the list of messages."
""
"Examples:"
" town nicethings"