rodo/init.rkt

47 lines
1.1 KiB
Racket

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