fixed formatting
parent
041ae59c96
commit
cf22f99d68
92
rodo.rkt
92
rodo.rkt
|
@ -15,89 +15,121 @@
|
||||||
|
|
||||||
(define messages
|
(define messages
|
||||||
(hash
|
(hash
|
||||||
'incorrect-usage (string-append
|
'incorrect-usage
|
||||||
|
(string-append
|
||||||
"> For usage type "
|
"> For usage type "
|
||||||
"`" program-name " -h`"
|
"`" program-name " -h`"
|
||||||
" or "
|
" or "
|
||||||
"`" program-name " --help`\n")
|
"`" program-name " --help`\n")
|
||||||
|
|
||||||
'creating (string-append
|
'creating
|
||||||
|
(string-append
|
||||||
"> Creating a "
|
"> Creating a "
|
||||||
program-directory
|
program-directory
|
||||||
" folder in "
|
" folder in "
|
||||||
program-path " ...\n")
|
program-path " ...\n")
|
||||||
|
|
||||||
'creation-error (string-append
|
'creation-error
|
||||||
|
(string-append
|
||||||
"> Error: Could not create "
|
"> Error: Could not create "
|
||||||
program-directory
|
program-directory
|
||||||
" in "
|
" in "
|
||||||
program-path ".\n"
|
program-path ".\n"
|
||||||
"> This may be due to directory permissions\n")
|
"> This may be due to directory permissions\n")
|
||||||
|
|
||||||
'already-exists (string-append
|
'already-exists
|
||||||
|
(string-append
|
||||||
"> "
|
"> "
|
||||||
program-directory
|
program-directory
|
||||||
" folder already exists in "
|
" folder already exists in "
|
||||||
program-path "\n")
|
program-path "\n")
|
||||||
|
|
||||||
'successfully-created (string-append
|
'successfully-created
|
||||||
|
(string-append
|
||||||
"> "
|
"> "
|
||||||
program-path program-directory
|
program-path program-directory
|
||||||
" has been successfully created\n")
|
" has been successfully created\n")
|
||||||
|
|
||||||
'not-found (string-append
|
'not-found
|
||||||
|
(string-append
|
||||||
"> "
|
"> "
|
||||||
program-directory
|
program-directory
|
||||||
" has not been setup in "
|
" has not been setup in "
|
||||||
program-path "\n")
|
program-path "\n")
|
||||||
|
|
||||||
'setup-y/n (string-append
|
'setup-y/n
|
||||||
|
(string-append
|
||||||
"> Would you like to set it up now? [y/n]\n")
|
"> Would you like to set it up now? [y/n]\n")
|
||||||
|
|
||||||
'try-initializing (string-append
|
'try-initializing
|
||||||
|
(string-append
|
||||||
"> Try typing "
|
"> Try typing "
|
||||||
"`" program-name
|
"`" program-name
|
||||||
" init` "
|
" init` "
|
||||||
"to set it up\n")
|
"to set it up\n")
|
||||||
|
|
||||||
'choose-y/n "> Error: Please choose y or n\n"
|
'choose-y/n
|
||||||
|
"> Error: Please choose y or n\n"
|
||||||
|
|
||||||
'item-added-prefix "> Added "
|
'item-added-prefix
|
||||||
'item-added-suffix " to list\n"
|
"> Added "
|
||||||
|
|
||||||
'item-removed-prefix "> Removed "
|
'item-added-suffix
|
||||||
'item-removed-suffix " from list\n"
|
" to list\n"
|
||||||
|
|
||||||
'terminating (string-append "> Exiting " program-name " ...\n")))
|
'item-removed-prefix
|
||||||
|
"> Removed "
|
||||||
|
|
||||||
|
'item-removed-suffix
|
||||||
|
" from list\n"
|
||||||
|
|
||||||
|
'terminating
|
||||||
|
(string-append
|
||||||
|
"> Exiting "
|
||||||
|
program-name
|
||||||
|
" ...\n")))
|
||||||
|
|
||||||
(define y/n
|
(define y/n
|
||||||
(hash
|
(hash
|
||||||
'yes '("yes" "Yes" "y" "Y")
|
'yes
|
||||||
'no '("no" "No" "n" "N")))
|
'("yes" "Yes" "y" "Y")
|
||||||
|
|
||||||
|
'no
|
||||||
|
'("no" "No" "n" "N")))
|
||||||
|
|
||||||
(define (open/create-file)
|
(define (open/create-file)
|
||||||
(let ([path (expand-user-path (string-append
|
(let
|
||||||
|
([path
|
||||||
|
(expand-user-path
|
||||||
|
(string-append
|
||||||
program-path
|
program-path
|
||||||
program-directory))])
|
program-directory))])
|
||||||
(let ([opened-file (open-output-file path
|
(let
|
||||||
|
([opened-file
|
||||||
|
(open-output-file path
|
||||||
#:mode 'text
|
#:mode 'text
|
||||||
#:exists 'can-update)])
|
#:exists 'can-update)])
|
||||||
(close-output-port opened-file))))
|
(close-output-port opened-file))))
|
||||||
|
|
||||||
(define (create-folder)
|
(define (create-folder)
|
||||||
(make-directory (expand-user-path (string-append
|
(make-directory
|
||||||
|
(expand-user-path
|
||||||
|
(string-append
|
||||||
program-path
|
program-path
|
||||||
program-directory))))
|
program-directory))))
|
||||||
|
|
||||||
(define (check-for-folder)
|
(define (check-for-folder)
|
||||||
(directory-exists? (expand-user-path (string-append
|
(directory-exists?
|
||||||
|
(expand-user-path
|
||||||
|
(string-append
|
||||||
program-path
|
program-path
|
||||||
program-directory))))
|
program-directory))))
|
||||||
|
|
||||||
(define (prompt-user chosen-message)
|
(define (prompt-user chosen-message)
|
||||||
(d-hash-ref messages chosen-message)
|
(d-hash-ref messages chosen-message)
|
||||||
(display "> ")
|
(display "> ")
|
||||||
(let ([user-input (read-line)])
|
(let
|
||||||
|
([user-input (read-line)])
|
||||||
(cond
|
(cond
|
||||||
[(member user-input (hash-ref y/n 'yes))
|
[(member user-input (hash-ref y/n 'yes))
|
||||||
(d-hash-ref messages 'creating)
|
(d-hash-ref messages 'creating)
|
||||||
|
@ -123,20 +155,28 @@
|
||||||
(d-hash-ref messages 'try-initializing))))
|
(d-hash-ref messages 'try-initializing))))
|
||||||
|
|
||||||
(define (check-args args)
|
(define (check-args args)
|
||||||
(let ([args-length (vector-length args)])
|
(let
|
||||||
|
([args-length (vector-length args)])
|
||||||
(cond
|
(cond
|
||||||
[(and (equal? args-length 2) (equal? (vector-member "add" args) 0))
|
[(and
|
||||||
|
(equal? args-length 2)
|
||||||
|
(equal? (vector-member "add" args) 0))
|
||||||
(add-item args)]
|
(add-item args)]
|
||||||
|
|
||||||
[(and (equal? args-length 2) (equal? (vector-member "remove" args) 0))
|
[(and
|
||||||
|
(equal? args-length 2)
|
||||||
|
(equal? (vector-member "remove" args) 0))
|
||||||
(d-hash-ref messages 'item-removed-prefix)
|
(d-hash-ref messages 'item-removed-prefix)
|
||||||
(d-vector-ref args 1)
|
(d-vector-ref args 1)
|
||||||
(d-hash-ref messages 'item-removed-suffix)]
|
(d-hash-ref messages 'item-removed-suffix)]
|
||||||
|
|
||||||
[(and (equal? args-length 1) (equal? (vector-member "init" args) 0))
|
[(and
|
||||||
|
(equal? args-length 1)
|
||||||
|
(equal? (vector-member "init" args) 0))
|
||||||
(todo-folder-exist?)]
|
(todo-folder-exist?)]
|
||||||
|
|
||||||
[else (d-hash-ref messages 'incorrect-usage)])))
|
[else
|
||||||
|
(d-hash-ref messages 'incorrect-usage)])))
|
||||||
|
|
||||||
(define (todo-folder-exist?)
|
(define (todo-folder-exist?)
|
||||||
(if (check-for-folder)
|
(if (check-for-folder)
|
||||||
|
|
Loading…
Reference in New Issue