hopefully fixed this dumpster fire of code up?

cleanup
m455 2021-04-15 09:31:07 -04:00
parent cf4af31cd7
commit 525326c5dd
1 changed files with 31 additions and 22 deletions

View File

@ -41,9 +41,12 @@
'couldnt-find-file
(format (string-append "Error: Couldn't find ~a" newline
"Either the file doesn't exist, or the permissions are incorrect." newline
"If the file exists, try running chmod 600 ~a")
"If the file exists, try running chmod 600 ~a"
"If the file doesn't exist, try running ~a ~a")
program-path
program-path)
program-path
program-name
init-command)
'error-something-exists
(format "Error: It looks like ~a already exists." program-path)
@ -107,7 +110,7 @@
(close-output-port (open-output-file string)))
(define (has-read-permissions? string)
(equal? program-permissions (file-or-directory-permissions string 'bits)))
(equal? read-permissions (file-or-directory-permissions string 'bits)))
;; ------------------------------------------------
;; init
@ -148,10 +151,13 @@
(displayln item))))
(define (ls)
(let ([listof-items (file->lines program-path)])
(if (null? listof-items)
(if (and (file-exists? program-file)
(has-read-permissions? program-file))
(let ([listof-items (file->lines program-path)])
(if (null? listof-items)
(displayln-messages-ref 'empty-list)
(ls/display-list listof-items))))
(ls/display-list listof-items)))
(displayln-messages-ref 'couldnt-file-file)))
;; ------------------------------------------------
;; rm
@ -168,22 +174,28 @@
(displayln-messages-ref 'error-item-not-found))))
(define (rm arg)
(let ([item-number (string->number arg)])
(if item-number
(rm/remove-nicething item-number)
(displayln-format-messages-ref 'error-not-a-number arg))))
(if (and (file-exists? program-file)
(has-read-permissions? program-file))
(let ([item-number (string->number arg)])
(if item-number
(rm/remove-nicething item-number)
(displayln-format-messages-ref 'error-not-a-number arg)))
(displayln-messages-ref 'couldnt-find-file)))
;; ------------------------------------------------
;; add
;; ------------------------------------------------
(define (add nicething)
;; The removing and adding of the '\n' is to
;; ensure only one '\n' exists at the end of the
;; item to be added.
(let* ([nicething-no-newline (string-replace nicething "\n" "")]
[nicething-newline (string-append nicething-no-newline "\n")])
(display-to-file nicething-newline program-path #:exists 'append)
(displayln-format-messages-ref 'added nicething-no-newline)))
(if (and (file-exists? program-file)
(has-read-permissions? program-file))
;; The removing and adding of the '\n' is to
;; ensure only one '\n' exists at the end of the
;; item to be added.
(let* ([nicething-no-newline (string-replace nicething "\n" "")]
[nicething-newline (string-append nicething-no-newline "\n")])
(display-to-file nicething-newline program-path #:exists 'append)
(displayln-format-messages-ref 'added nicething-no-newline))
(displayln-messages-ref 'couldnt-find-file)))
;; ------------------------------------------------
;; random message
@ -193,7 +205,7 @@
;; `#:build? #t` Builds full paths for all items listed in /home/
[listof-home-directories (directory-list root-home #:build? #t)]
[listof-nicethings-paths (map (lambda (x) (build-path x program-file))
(listof-home-directories))]
listof-home-directories)]
[paths-with-nicethings (filter file-exists? listof-nicethings-paths)]
[paths-readable (filter has-read-permissions? paths-with-nicethings)]
[listof-nicethings (apply append (map file->lines paths-readable))]
@ -243,9 +255,6 @@
[(vector _ ...) (displayln-messages-ref 'error-incorrect-usage)]))
(define (main vectorof-args)
(if (and (file-exists program-file)
(has-read-permissions? program-file))
(process-args vectorof-args)
(displayln-messages-ref 'couldnt-find-file)))
(process-args vectorof-args))
(main (current-command-line-arguments))