cleaned up hash-ref messages
parent
fe91538eaa
commit
8b5ae8accd
6
args.rkt
6
args.rkt
|
@ -12,12 +12,12 @@
|
||||||
(let ([args-length (length args)])
|
(let ([args-length (length args)])
|
||||||
(cond
|
(cond
|
||||||
[(equal? args-length 0)
|
[(equal? args-length 0)
|
||||||
(utils:display-hash-ref messages:messages 'show-usage)]
|
(utils:display-messages '(show-usage))]
|
||||||
|
|
||||||
;; help-command
|
;; help-command
|
||||||
[(and (equal? args-length 1)
|
[(and (equal? args-length 1)
|
||||||
(member (list-ref args 0) config:help-commands))
|
(member (list-ref args 0) config:help-commands))
|
||||||
(utils:display-hash-ref messages:messages 'show-help)]
|
(utils:display-messages '(show-help))]
|
||||||
|
|
||||||
;; initialize-command
|
;; initialize-command
|
||||||
[(and (equal? args-length 1)
|
[(and (equal? args-length 1)
|
||||||
|
@ -42,4 +42,4 @@
|
||||||
(zero? (string->number (list-ref args 1)))))
|
(zero? (string->number (list-ref args 1)))))
|
||||||
(utils:check-remove-conditions args)]
|
(utils:check-remove-conditions args)]
|
||||||
|
|
||||||
[else (utils:display-hash-ref messages:messages 'show-usage)])))
|
[else (utils:display-messages '(show-usage))])))
|
||||||
|
|
14
init.rkt
14
init.rkt
|
@ -7,26 +7,26 @@
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define (create-initialization-contents)
|
(define (create-initialization-contents)
|
||||||
(utils:display-hash-ref messages:messages 'creating)
|
(utils:display-messages '(creating))
|
||||||
(utils:create-directory-700 config:program-directory)
|
(utils:create-directory-700 config:program-directory)
|
||||||
(utils:create-file-600 config:list-file)
|
(utils:create-file-600 config:list-file)
|
||||||
(if (and (directory-exists? config:program-directory)
|
(if (and (directory-exists? config:program-directory)
|
||||||
(file-exists? config:list-file))
|
(file-exists? config:list-file))
|
||||||
(utils:display-hash-ref messages:messages 'successfully-created)
|
(utils:display-messages '(successfully-created))
|
||||||
;; Otherwise
|
;; Otherwise
|
||||||
(utils:display-hash-ref messages:messages 'creation-error)))
|
(utils:display-messages '(creation-error))))
|
||||||
|
|
||||||
(define (initialize)
|
(define (initialize)
|
||||||
(utils:display-hash-ref messages:messages 'init-y/n)
|
(utils:display-messages '(init-y/n))
|
||||||
(display "> ")
|
(display "> ")
|
||||||
(let ([user-input (read-line)])
|
(let ([user-input (read-line)])
|
||||||
(cond [(member user-input (hash-ref messages:y/n 'yes))
|
(cond [(member user-input (hash-ref messages:y/n 'yes))
|
||||||
(create-initialization-contents)]
|
(create-initialization-contents)]
|
||||||
[(member user-input (hash-ref messages:y/n 'no))
|
[(member user-input (hash-ref messages:y/n 'no))
|
||||||
(utils:display-hash-ref messages:messages 'terminating)]
|
(utils:display-messages '(terminating))]
|
||||||
[else (utils:display-hash-ref messages:messages 'choose-y/n)])))
|
[else (utils:display-messages '(choose-y/n))])))
|
||||||
|
|
||||||
(define (check-initialize-conditions)
|
(define (check-initialize-conditions)
|
||||||
(if (file-exists? config:list-file)
|
(if (file-exists? config:list-file)
|
||||||
(utils:display-hash-ref messages:messages 'file-already-exists)
|
(utils:display-messages '(file-already-exists))
|
||||||
(initialize)))
|
(initialize)))
|
||||||
|
|
21
utils.rkt
21
utils.rkt
|
@ -17,12 +17,9 @@
|
||||||
(make-directory a-directory)
|
(make-directory a-directory)
|
||||||
(file-or-directory-permissions a-directory #o700))
|
(file-or-directory-permissions a-directory #o700))
|
||||||
|
|
||||||
(define (display-hash-ref hash-list key)
|
(define (display-messages key-list)
|
||||||
(display (hash-ref hash-list key)))
|
|
||||||
|
|
||||||
(define (display-hash-ref-multi hash-list key-list)
|
|
||||||
(for ([key key-list])
|
(for ([key key-list])
|
||||||
(display (hash-ref hash-list key))))
|
(display (hash-ref messages:messages key))))
|
||||||
|
|
||||||
(define (list->ascending-numbers lst)
|
(define (list->ascending-numbers lst)
|
||||||
(list:range (length lst)))
|
(list:range (length lst)))
|
||||||
|
@ -61,13 +58,13 @@
|
||||||
;; If exists and empty
|
;; If exists and empty
|
||||||
[(and (file-exists? config:list-file)
|
[(and (file-exists? config:list-file)
|
||||||
(null? (file:file->lines config:list-file)))
|
(null? (file:file->lines config:list-file)))
|
||||||
(display-hash-ref messages:messages 'empty-list)]
|
(display-messages '(empty-list))]
|
||||||
|
|
||||||
;; If not exist
|
;; If not exist
|
||||||
[(and (not (file-exists? config:list-file)))
|
[(and (not (file-exists? config:list-file)))
|
||||||
(display-hash-ref-multi messages:messages '(file-not-found try-init))]
|
(display-messages '(file-not-found try-init))]
|
||||||
|
|
||||||
[else (display-hash-ref messages:messages 'show-usage)]))
|
[else (display-messages '(show-usage))]))
|
||||||
|
|
||||||
(define (append-element-to-end-of-list lst item-to-add)
|
(define (append-element-to-end-of-list lst item-to-add)
|
||||||
(reverse (cons item-to-add (reverse (file:file->lines lst)))))
|
(reverse (cons item-to-add (reverse (file:file->lines lst)))))
|
||||||
|
@ -85,7 +82,7 @@
|
||||||
(if (and (file-exists? config:list-file))
|
(if (and (file-exists? config:list-file))
|
||||||
(add-item-to-list args)
|
(add-item-to-list args)
|
||||||
;; Otherwise
|
;; Otherwise
|
||||||
(display-hash-ref-multi messages:messages '(file-not-found try-init))))
|
(display-messages '(file-not-found try-init))))
|
||||||
|
|
||||||
(define (remove-item-from-list user-args)
|
(define (remove-item-from-list user-args)
|
||||||
(let* ([item-to-remove (list-ref (file:file->lines config:list-file) user-args)]
|
(let* ([item-to-remove (list-ref (file:file->lines config:list-file) user-args)]
|
||||||
|
@ -102,7 +99,7 @@
|
||||||
[(and (directory-exists? config:program-directory)
|
[(and (directory-exists? config:program-directory)
|
||||||
(file-exists? config:list-file)
|
(file-exists? config:list-file)
|
||||||
(null? config:list-file))
|
(null? config:list-file))
|
||||||
(display-hash-ref messages:messages 'empty-list)]
|
(display-messages '(empty-list))]
|
||||||
|
|
||||||
;; If directory and file exist, and file is not empty
|
;; If directory and file exist, and file is not empty
|
||||||
[(and (directory-exists? config:program-directory)
|
[(and (directory-exists? config:program-directory)
|
||||||
|
@ -114,9 +111,9 @@
|
||||||
(if (not (> user-args list-length))
|
(if (not (> user-args list-length))
|
||||||
(remove-item-from-list user-args)
|
(remove-item-from-list user-args)
|
||||||
;; Otherwise
|
;; Otherwise
|
||||||
(display-hash-ref messages:messages 'item-not-found)))]
|
(display-messages '(item-not-found))))]
|
||||||
|
|
||||||
;; If directory and file don't exist
|
;; If directory and file don't exist
|
||||||
[(and (not (directory-exists? config:program-directory))
|
[(and (not (directory-exists? config:program-directory))
|
||||||
(not (file-exists? config:list-file)))
|
(not (file-exists? config:list-file)))
|
||||||
(display-hash-ref-multi messages:messages '(file-not-found try-init))]))
|
(display-messages '(file-not-found try-init))]))
|
||||||
|
|
Loading…
Reference in New Issue