prefixed init.rkt

main
m455 2018-10-10 14:42:13 -04:00
parent 2e6091c1c8
commit 15709187f7
1 changed files with 28 additions and 29 deletions

View File

@ -1,46 +1,45 @@
#lang racket/base #lang racket/base
(require racket/file (require (prefix-in file: racket/file)
"config.rkt" (prefix-in config: "config.rkt")
"util.rkt" (prefix-in util: "util.rkt")
"messages.rkt") (prefix-in messages: "messages.rkt"))
(provide (all-defined-out)) (provide (all-defined-out))
(define (initialize-file) (define (initialize-file)
(display-to-file (file:display-to-file
"--Do not edit this file--\n" "--Do not edit this file--\n"
path config:path
#:mode 'text #:mode 'text
#:exists 'replace)) #:exists 'replace))
(define (init-prompt hash-list key) (define (init-prompt hash-list key)
(display-hash-ref hash-list key) (util:display-hash-ref hash-list key)
(display "> ") (display "> ")
(let (let
([user-input (read-line)]) ([user-input (read-line)])
(cond (cond
[(member user-input (hash-ref y/n 'yes)) [(member user-input (hash-ref messages:y/n 'yes))
(display-hash-ref messages 'creating-folder) (util:display-hash-ref messages:messages 'creating-folder)
(display-hash-ref messages 'creating-file) (util:display-hash-ref messages:messages 'creating-file)
(create-folder) (util:create-folder)
(create-file) (util:create-file)
(initialize-file) (initialize-file)
(if (if (and
(and (util:check-for-folder)
(check-for-folder) (util:check-for-file))
(check-for-file)) (util:display-hash-ref messages:messages 'successfully-created)
(display-hash-ref messages 'successfully-created) (util:display-hash-ref messages:messages 'creation-error))]
(display-hash-ref messages 'creation-error))]
[(member user-input (hash-ref y/n 'no)) [(member user-input (hash-ref messages:y/n 'no))
(display-hash-ref messages 'terminating)] (util:display-hash-ref messages:messages 'terminating)]
[else [else
(init-prompt messages 'choose-y/n)]))) (init-prompt messages:messages 'choose-y/n)])))
(define (initialize) (define (initialize)
(if (check-for-file) (if (util:check-for-file)
(display-hash-ref messages 'file-already-exists) (util:display-hash-ref messages:messages 'file-already-exists)
(begin (begin
(init-prompt messages 'init-y/n)))) (init-prompt messages:messages 'init-y/n))))