|
|
@ -8,17 +8,17 @@
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; Constants
|
|
|
|
;; Constants
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define help-command-1 "help")
|
|
|
|
(define command-help-1 "help")
|
|
|
|
(define help-command-2 "--help")
|
|
|
|
(define command-help-2 "--help")
|
|
|
|
(define help-command-3 "-h")
|
|
|
|
(define command-help-3 "-h")
|
|
|
|
(define init-command "init")
|
|
|
|
(define command-init "init")
|
|
|
|
(define ls-command "ls")
|
|
|
|
(define command-ls "ls")
|
|
|
|
(define rm-command "rm")
|
|
|
|
(define command-rm "rm")
|
|
|
|
(define add-command "add")
|
|
|
|
(define command-add "add")
|
|
|
|
(define program-name "nicethings")
|
|
|
|
(define program-name "nicethings")
|
|
|
|
(define program-file (string-append "." program-name))
|
|
|
|
(define program-file (string-append "." program-name))
|
|
|
|
(define program-path (path->string (build-path (find-system-path 'home-dir) program-file)))
|
|
|
|
(define program-path (path->string (build-path (find-system-path 'home-dir) program-file)))
|
|
|
|
(define read-permissions 444)
|
|
|
|
(define read-permissions 420)
|
|
|
|
(define newline "\n")
|
|
|
|
(define newline "\n")
|
|
|
|
(define double-newline "\n\n")
|
|
|
|
(define double-newline "\n\n")
|
|
|
|
|
|
|
|
|
|
|
@ -30,13 +30,13 @@
|
|
|
|
(format (string-append "Error: Too many arguments." newline
|
|
|
|
(format (string-append "Error: Too many arguments." newline
|
|
|
|
"Try running '~a ~a' for more information.")
|
|
|
|
"Try running '~a ~a' for more information.")
|
|
|
|
program-name
|
|
|
|
program-name
|
|
|
|
help-command-1)
|
|
|
|
command-help-1)
|
|
|
|
|
|
|
|
|
|
|
|
'error-incorrect-usage
|
|
|
|
'error-incorrect-usage
|
|
|
|
(format (string-append "Error: Incorrect usage." newline
|
|
|
|
(format (string-append "Error: Incorrect usage." newline
|
|
|
|
"Try running '~a ~a' for more information.")
|
|
|
|
"Try running '~a ~a' for more information.")
|
|
|
|
program-name
|
|
|
|
program-name
|
|
|
|
help-command-1)
|
|
|
|
command-help-1)
|
|
|
|
|
|
|
|
|
|
|
|
'couldnt-find-file
|
|
|
|
'couldnt-find-file
|
|
|
|
(format (string-append "Error: Couldn't find ~a" newline
|
|
|
|
(format (string-append "Error: Couldn't find ~a" newline
|
|
|
@ -46,7 +46,7 @@
|
|
|
|
program-path
|
|
|
|
program-path
|
|
|
|
program-path
|
|
|
|
program-path
|
|
|
|
program-name
|
|
|
|
program-name
|
|
|
|
init-command)
|
|
|
|
command-init)
|
|
|
|
|
|
|
|
|
|
|
|
'error-something-exists
|
|
|
|
'error-something-exists
|
|
|
|
(format "Error: It looks like ~a already exists." program-path)
|
|
|
|
(format "Error: It looks like ~a already exists." program-path)
|
|
|
@ -56,7 +56,7 @@
|
|
|
|
"Try running '~a ~a'.")
|
|
|
|
"Try running '~a ~a'.")
|
|
|
|
program-path
|
|
|
|
program-path
|
|
|
|
program-name
|
|
|
|
program-name
|
|
|
|
init-command)
|
|
|
|
command-init)
|
|
|
|
|
|
|
|
|
|
|
|
'error-item-not-found
|
|
|
|
'error-item-not-found
|
|
|
|
"Error: Item not found."
|
|
|
|
"Error: Item not found."
|
|
|
@ -151,8 +151,8 @@
|
|
|
|
(displayln item))))
|
|
|
|
(displayln item))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (ls)
|
|
|
|
(define (ls)
|
|
|
|
(if (and (file-exists? program-file)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
(has-read-permissions? program-file))
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
(if (null? listof-items)
|
|
|
|
(if (null? listof-items)
|
|
|
|
(displayln-messages-ref 'empty-list)
|
|
|
|
(displayln-messages-ref 'empty-list)
|
|
|
@ -165,6 +165,7 @@
|
|
|
|
(define (rm/remove-nicething item-number)
|
|
|
|
(define (rm/remove-nicething item-number)
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
(if (and (not (null? listof-items))
|
|
|
|
(if (and (not (null? listof-items))
|
|
|
|
|
|
|
|
(exact? item-number)
|
|
|
|
(>= item-number 0)
|
|
|
|
(>= item-number 0)
|
|
|
|
(< item-number (length listof-items)))
|
|
|
|
(< item-number (length listof-items)))
|
|
|
|
(let* ([item-to-remove (list-ref listof-items item-number)]
|
|
|
|
(let* ([item-to-remove (list-ref listof-items item-number)]
|
|
|
@ -174,8 +175,8 @@
|
|
|
|
(displayln-messages-ref 'error-item-not-found))))
|
|
|
|
(displayln-messages-ref 'error-item-not-found))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (rm arg)
|
|
|
|
(define (rm arg)
|
|
|
|
(if (and (file-exists? program-file)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
(has-read-permissions? program-file))
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
(let ([item-number (string->number arg)])
|
|
|
|
(let ([item-number (string->number arg)])
|
|
|
|
(if item-number
|
|
|
|
(if item-number
|
|
|
|
(rm/remove-nicething item-number)
|
|
|
|
(rm/remove-nicething item-number)
|
|
|
@ -186,8 +187,8 @@
|
|
|
|
;; add
|
|
|
|
;; add
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (add nicething)
|
|
|
|
(define (add nicething)
|
|
|
|
(if (and (file-exists? program-file)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
(has-read-permissions? program-file))
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
;; The removing and adding of the '\n' is to
|
|
|
|
;; The removing and adding of the '\n' is to
|
|
|
|
;; ensure only one '\n' exists at the end of the
|
|
|
|
;; ensure only one '\n' exists at the end of the
|
|
|
|
;; item to be added.
|
|
|
|
;; item to be added.
|
|
|
@ -212,8 +213,9 @@
|
|
|
|
[list-length (length listof-nicethings)])
|
|
|
|
[list-length (length listof-nicethings)])
|
|
|
|
(when (not (zero? list-length))
|
|
|
|
(when (not (zero? list-length))
|
|
|
|
(let* ([random-number (random list-length)]
|
|
|
|
(let* ([random-number (random list-length)]
|
|
|
|
[random-nicething (list-ref listof-nicethings random-number)])
|
|
|
|
[random-nicething (list-ref listof-nicethings random-number)]
|
|
|
|
(displayln random-nicething)))))
|
|
|
|
[nicething-trimmed (string-replace random-nicething "\n" "")])
|
|
|
|
|
|
|
|
(displayln nicething-trimmed)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; help
|
|
|
|
;; help
|
|
|
@ -228,29 +230,29 @@
|
|
|
|
"Commands:" newline
|
|
|
|
"Commands:" newline
|
|
|
|
" No command - Displays a random nicething from a random user." newline
|
|
|
|
" No command - Displays a random nicething from a random user." newline
|
|
|
|
(format " ~a - Creates a file in ~a, which allows you to contribute to the town-wide list of nicethings."
|
|
|
|
(format " ~a - Creates a file in ~a, which allows you to contribute to the town-wide list of nicethings."
|
|
|
|
init-command
|
|
|
|
command-init
|
|
|
|
program-path) newline
|
|
|
|
program-path) newline
|
|
|
|
(format " ~a - Adds a nicething to your list." add-command) newline
|
|
|
|
(format " ~a - Adds a nicething to your list." command-add) newline
|
|
|
|
(format " ~a - Prints a numbered list of the nicethings you've added." ls-command) newline
|
|
|
|
(format " ~a - Prints a numbered list of the nicethings you've added." command-ls) newline
|
|
|
|
(format " ~a - Removes a nicething from your list." rm-command)
|
|
|
|
(format " ~a - Removes a nicething from your list." command-rm)
|
|
|
|
double-newline
|
|
|
|
double-newline
|
|
|
|
|
|
|
|
|
|
|
|
"Examples:" newline
|
|
|
|
"Examples:" newline
|
|
|
|
(format " ~a" program-name) newline
|
|
|
|
(format " ~a" program-name) newline
|
|
|
|
(format " ~a ~a" program-name init-command) newline
|
|
|
|
(format " ~a ~a" program-name command-init) newline
|
|
|
|
(format " ~a ~a \"You are wonderful\"" program-name add-command) newline
|
|
|
|
(format " ~a ~a \"You are wonderful\"" program-name command-add) newline
|
|
|
|
(format " ~a ~a" program-name ls-command) newline
|
|
|
|
(format " ~a ~a" program-name command-ls) newline
|
|
|
|
(format " ~a ~a 2" program-name rm-command))))
|
|
|
|
(format " ~a ~a 2" program-name command-rm))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (process-args vectorof-args)
|
|
|
|
(define (process-args vectorof-args)
|
|
|
|
(match vectorof-args
|
|
|
|
(match vectorof-args
|
|
|
|
[(or (vector (== help-command-1))
|
|
|
|
[(or (vector (== command-help-1))
|
|
|
|
(vector (== help-command-2))
|
|
|
|
(vector (== command-help-2))
|
|
|
|
(vector (== help-command-3))) (help)]
|
|
|
|
(vector (== command-help-3))) (help)]
|
|
|
|
[(vector (== ls-command)) (ls)]
|
|
|
|
[(vector (== command-ls)) (ls)]
|
|
|
|
[(vector (== init-command)) (init)]
|
|
|
|
[(vector (== command-init)) (init)]
|
|
|
|
[(vector (== add-command) a) (add a)]
|
|
|
|
[(vector (== command-add) a) (add a)]
|
|
|
|
[(vector (== rm-command) a) (rm a)]
|
|
|
|
[(vector (== command-rm) a) (rm a)]
|
|
|
|
[_ (random-message)]
|
|
|
|
[_ (random-message)]
|
|
|
|
[(vector _ ...) (displayln-messages-ref 'error-incorrect-usage)]))
|
|
|
|
[(vector _ ...) (displayln-messages-ref 'error-incorrect-usage)]))
|
|
|
|
|
|
|
|
|
|
|
|