don't really remember what I changed lol

main
m455 2020-04-13 10:45:11 -04:00
parent 3004835bc0
commit 84cb77ce95
No known key found for this signature in database
GPG Key ID: 7FE7101DC135DE1F
2 changed files with 16 additions and 14 deletions

View File

@ -12,30 +12,32 @@
(let ([args-length (length args)] (let ([args-length (length args)]
[is-member? (lambda (command) (member (list-ref args 0) command))]) [is-member? (lambda (command) (member (list-ref args 0) command))])
(cond (cond
;; if no args
[(equal? args-length 0) [(equal? args-length 0)
(utils:display-messages '(show-usage))] (utils:display-messages '(show-usage))]
;; help ;; if one arg, and arg is the help command
[(and (equal? args-length 1) [(and (equal? args-length 1)
(is-member? config:help-commands)) (is-member? config:help-commands))
(utils:display-messages '(show-help))] (utils:display-messages '(show-help))]
;; initialize ;; if one arg, and arg is the initialize command
[(and (equal? args-length 1) [(and (equal? args-length 1)
(is-member? config:initialize-commands)) (is-member? config:initialize-commands))
(init:check-initialize-conditions)] (init:check-initialize-conditions)]
;; add ;; if two args, and the add command exists in one of those args
[(and (>= args-length 2) [(and (>= args-length 2)
(is-member? config:add-commands)) (is-member? config:add-commands))
(utils:check-add-conditions args)] (utils:check-add-conditions args)]
;; list ;; if one arg, and arg is the list command
[(and (equal? args-length 1) [(and (equal? args-length 1)
(is-member? config:list-commands)) (is-member? config:list-commands))
(utils:check-list-conditions)] (utils:check-list-conditions)]
;; remove ;; if two args, and the remove command exists in one of those args
[(and (>= args-length 2)
[(and (equal? args-length 2) [(and (equal? args-length 2)
(is-member? config:remove-commands) (is-member? config:remove-commands)
(real? (string->number (list-ref args 1))) (real? (string->number (list-ref args 1)))

View File

@ -8,11 +8,13 @@
(provide (all-defined-out)) (provide (all-defined-out))
;; This may be affected by the user's umask
(define (file-create-600 a-file) (define (file-create-600 a-file)
(let ([opened-file (open-output-file a-file #:mode 'text #:exists 'truncate)]) (let ([opened-file (open-output-file a-file #:mode 'text #:exists 'truncate)])
(close-output-port opened-file)) (close-output-port opened-file))
(file-or-directory-permissions a-file #o600)) (file-or-directory-permissions a-file #o600))
;; This may be affected by the user's umask
(define (directory-create-700 a-directory) (define (directory-create-700 a-directory)
(make-directory a-directory) (make-directory a-directory)
(file-or-directory-permissions a-directory #o700)) (file-or-directory-permissions a-directory #o700))
@ -34,9 +36,10 @@
lst)) lst))
(define (file->vertically-numbered-list a-file) (define (file->vertically-numbered-list a-file)
(string:string-join (list->numbered-list (file:file->lines a-file)) (string:string-join
"\n" (list->numbered-list (file:file->lines a-file))
#:after-last "\n")) "\n"
#:after-last "\n"))
(define (surround-with-quotation-marks item) (define (surround-with-quotation-marks item)
(string-append "\"" item "\"")) (string-append "\"" item "\""))
@ -79,9 +82,7 @@
(define (check-add-conditions args) (define (check-add-conditions args)
(if (and (file-exists? config:list-file)) (if (and (file-exists? config:list-file))
(item-add args) (item-add args)
;; Otherwise (display-messages '(file-not-found try-init))))
(display-messages '(file-not-found
try-init))))
(define (item-remove args) (define (item-remove args)
(let* ([item-to-remove (list-ref (file:file->lines config:list-file) args)] (let* ([item-to-remove (list-ref (file:file->lines config:list-file) args)]
@ -97,7 +98,7 @@
(null? config:list-file)) (null? config:list-file))
(display-messages '(empty-list))] (display-messages '(empty-list))]
;; If directory and file exist, and file is not empty ;; If directory and file exist, but file is not empty
[(and (directory-exists? config:program-directory) [(and (directory-exists? config:program-directory)
(file-exists? config:list-file) (file-exists? config:list-file)
(not (null? config:list-file))) (not (null? config:list-file)))
@ -106,10 +107,9 @@
[list-length (sub1 (length (file:file->lines config:list-file)))]) [list-length (sub1 (length (file:file->lines config:list-file)))])
(if (not (> args list-length)) (if (not (> args list-length))
(item-remove args) (item-remove args)
;; Otherwise
(display-messages '(item-not-found))))] (display-messages '(item-not-found))))]
;; If directory and file don't exist ;; If directory and file does not 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-messages '(file-not-found try-init))])) (display-messages '(file-not-found try-init))]))