rodo/init.rkt

32 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))
(define (init-prompt hash-list key)
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref hash-list key)
(display "> ")
2019-11-04 02:32:11 +00:00
(let ([user-input (read-line)])
(cond [(member user-input (hash-ref messages:y/n 'yes))
(begin
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'creating)
2019-11-15 12:37:40 +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))
2019-11-13 18:59:02 +00:00
(utils:display-hash-ref messages:messages 'successfully-created)
(utils:display-hash-ref messages:messages 'creation-error)))]
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-04 02:32:11 +00:00
[else
(init-prompt messages:messages 'choose-y/n)])))
(define (initialize)
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)
(begin
(init-prompt messages:messages 'init-y/n))))