rodo/init.rkt

33 lines
1.2 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)
(utils:display-hash-ref messages:messages 'creating)
(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))
(utils:display-hash-ref messages:messages 'successfully-created)
;; Otherwise
(utils:display-hash-ref messages:messages 'creation-error)))
(define (initialize)
(utils:display-hash-ref messages: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))
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'terminating)]
2019-11-22 18:35:25 +00:00
[else (utils:display-hash-ref messages: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)
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'file-already-exists)
2019-11-22 18:35:25 +00:00
(initialize)))