can now create files and check for them

main
m455 2018-04-06 10:30:38 -04:00
parent 7510ad5fa0
commit 4ec14ada08
1 changed files with 34 additions and 9 deletions

View File

@ -6,6 +6,7 @@
(define program-name "rodo") (define program-name "rodo")
(define program-directory ".rodo/") (define program-directory ".rodo/")
(define program-path "~/") (define program-path "~/")
(define program-file "todo-list")
(define (d-hash-ref hash-list key) (define (d-hash-ref hash-list key)
(display (hash-ref hash-list key))) (display (hash-ref hash-list key)))
@ -22,13 +23,21 @@
" or " " or "
"`" program-name " --help`\n") "`" program-name " --help`\n")
'creating 'creating-folder
(string-append (string-append
"> Creating a " "> creating a "
program-directory program-directory
" folder in " " folder in "
program-path " ...\n") program-path " ...\n")
'creating-file
(string-append
"> creating a "
program-file
" folder in "
program-path
program-directory " ...\n")
'creation-error 'creation-error
(string-append (string-append
"> Error: Could not create " "> Error: Could not create "
@ -47,7 +56,9 @@
'successfully-created 'successfully-created
(string-append (string-append
"> " "> "
program-path program-directory program-path
program-directory
program-file
" has been successfully created\n") " has been successfully created\n")
'not-found 'not-found
@ -97,13 +108,14 @@
'no 'no
'("no" "No" "n" "N"))) '("no" "No" "n" "N")))
(define (open/create-file) (define (create-file)
(let (let
([path ([path
(expand-user-path (expand-user-path
(string-append (string-append
program-path program-path
program-directory))]) program-directory
program-file))])
(let (let
([opened-file ([opened-file
(open-output-file path (open-output-file path
@ -118,6 +130,14 @@
program-path program-path
program-directory)))) program-directory))))
(define (check-for-file)
(file-exists?
(expand-user-path
(string-append
program-path
program-directory
program-file))))
(define (check-for-folder) (define (check-for-folder)
(directory-exists? (directory-exists?
(expand-user-path (expand-user-path
@ -132,9 +152,14 @@
([user-input (read-line)]) ([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-folder)
(d-hash-ref messages 'creating-file)
(create-folder) (create-folder)
(if (check-for-folder) (create-file)
(if
(and
(check-for-folder)
(check-for-file))
(d-hash-ref messages 'successfully-created) (d-hash-ref messages 'successfully-created)
(d-hash-ref messages 'creation-error))] (d-hash-ref messages 'creation-error))]
@ -181,12 +206,12 @@
[(and [(and
(equal? args-length 1) (equal? args-length 1)
(equal? (vector-member "init" args) 0)) (equal? (vector-member "init" args) 0))
(todo-folder-exist?)] (todo-already-exists?)]
[else [else
(d-hash-ref messages 'incorrect-usage)]))) (d-hash-ref messages 'incorrect-usage)])))
(define (todo-folder-exist?) (define (todo-already-exists?)
(if (check-for-folder) (if (check-for-folder)
(d-hash-ref messages 'already-exists) (d-hash-ref messages 'already-exists)
(begin (begin