From 84cb77ce9512db4f3e75aac0d187b1b6c318043b Mon Sep 17 00:00:00 2001 From: m455 Date: Mon, 13 Apr 2020 10:45:11 -0400 Subject: [PATCH] don't really remember what I changed lol --- src/args.rkt | 12 +++++++----- src/utils.rkt | 18 +++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/args.rkt b/src/args.rkt index 1f89a73..fcefd04 100644 --- a/src/args.rkt +++ b/src/args.rkt @@ -12,30 +12,32 @@ (let ([args-length (length args)] [is-member? (lambda (command) (member (list-ref args 0) command))]) (cond + ;; if no args [(equal? args-length 0) (utils:display-messages '(show-usage))] - ;; help + ;; if one arg, and arg is the help command [(and (equal? args-length 1) (is-member? config:help-commands)) (utils:display-messages '(show-help))] - ;; initialize + ;; if one arg, and arg is the initialize command [(and (equal? args-length 1) (is-member? config:initialize-commands)) (init:check-initialize-conditions)] - ;; add + ;; if two args, and the add command exists in one of those args [(and (>= args-length 2) (is-member? config:add-commands)) (utils:check-add-conditions args)] - ;; list + ;; if one arg, and arg is the list command [(and (equal? args-length 1) (is-member? config:list-commands)) (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) (is-member? config:remove-commands) (real? (string->number (list-ref args 1))) diff --git a/src/utils.rkt b/src/utils.rkt index 0db7cc6..81d5495 100644 --- a/src/utils.rkt +++ b/src/utils.rkt @@ -8,11 +8,13 @@ (provide (all-defined-out)) +;; This may be affected by the user's umask (define (file-create-600 a-file) (let ([opened-file (open-output-file a-file #:mode 'text #:exists 'truncate)]) (close-output-port opened-file)) (file-or-directory-permissions a-file #o600)) +;; This may be affected by the user's umask (define (directory-create-700 a-directory) (make-directory a-directory) (file-or-directory-permissions a-directory #o700)) @@ -34,9 +36,10 @@ lst)) (define (file->vertically-numbered-list a-file) - (string:string-join (list->numbered-list (file:file->lines a-file)) - "\n" - #:after-last "\n")) + (string:string-join + (list->numbered-list (file:file->lines a-file)) + "\n" + #:after-last "\n")) (define (surround-with-quotation-marks item) (string-append "\"" item "\"")) @@ -79,9 +82,7 @@ (define (check-add-conditions args) (if (and (file-exists? config:list-file)) (item-add args) - ;; Otherwise - (display-messages '(file-not-found - try-init)))) + (display-messages '(file-not-found try-init)))) (define (item-remove args) (let* ([item-to-remove (list-ref (file:file->lines config:list-file) args)] @@ -97,7 +98,7 @@ (null? config:list-file)) (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) (file-exists? config:list-file) (not (null? config:list-file))) @@ -106,10 +107,9 @@ [list-length (sub1 (length (file:file->lines config:list-file)))]) (if (not (> args list-length)) (item-remove args) - ;; Otherwise (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)) (not (file-exists? config:list-file))) (display-messages '(file-not-found try-init))]))