rodo/init.rkt

33 lines
1.1 KiB
Racket
Raw Normal View History

#lang racket/base
(require (prefix-in config: "config.rkt")
(prefix-in messages: "messages.rkt")
2019-11-13 18:59:02 +00:00
(prefix-in utils: "utils.rkt"))
(provide (all-defined-out))
2019-11-22 18:35:25 +00:00
(define (create-initialization-contents)
2020-01-03 19:21:08 +00:00
(utils:display-messages '(creating))
2019-11-22 18:35:25 +00:00
(utils:create-directory-700 config:program-directory)
(utils:create-file-600 config:list-file)
(if (and (directory-exists? config:program-directory)
(file-exists? config:list-file))
2020-01-03 19:21:08 +00:00
(utils:display-messages '(successfully-created))
2019-11-22 18:35:25 +00:00
;; Otherwise
2020-01-03 19:21:08 +00:00
(utils:display-messages '(creation-error))))
2019-11-22 18:35:25 +00:00
(define (initialize)
2020-01-03 19:21:08 +00:00
(utils:display-messages '(init-y/n))
(display "> ")
2019-11-04 02:32:11 +00:00
(let ([user-input (read-line)])
(cond [(member user-input (hash-ref messages:y/n 'yes))
2019-11-22 18:35:25 +00:00
(create-initialization-contents)]
2019-11-04 02:32:11 +00:00
[(member user-input (hash-ref messages:y/n 'no))
2020-01-03 19:21:08 +00:00
(utils:display-messages '(terminating))]
[else (utils:display-messages '(choose-y/n))])))
2019-11-22 18:35:25 +00:00
(define (check-initialize-conditions)
2019-11-15 12:37:40 +00:00
(if (file-exists? config:list-file)
2020-01-03 19:21:08 +00:00
(utils:display-messages '(file-already-exists))
2019-11-22 18:35:25 +00:00
(initialize)))