|
|
@ -8,92 +8,91 @@
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; 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 (build-path (find-system-path 'home-dir) program-file))
|
|
|
|
(define program-path (path->string (build-path (find-system-path 'home-dir) program-file)))
|
|
|
|
(define program-permissions 420) ;; 644/-rw-r--r-- permissions
|
|
|
|
(define read-permissions 420)
|
|
|
|
(define newline "\n")
|
|
|
|
(define newline "\n")
|
|
|
|
(define double-newline "\n\n")
|
|
|
|
(define double-newline "\n\n")
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; Messages
|
|
|
|
;; Messages
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define messages
|
|
|
|
(define messages
|
|
|
|
(hash
|
|
|
|
(hash 'error-too-many-arguments
|
|
|
|
'error-too-many-arguments
|
|
|
|
(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
|
|
|
|
command-help-1)
|
|
|
|
help-command-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)
|
|
|
|
|
|
|
|
|
|
|
|
'error-file-already-exists
|
|
|
|
'couldnt-find-file
|
|
|
|
(format "Error: The file '~a' already exists." program-path)
|
|
|
|
(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 doesn't exist, try running ~a ~a")
|
|
|
|
|
|
|
|
program-path
|
|
|
|
|
|
|
|
program-path
|
|
|
|
|
|
|
|
program-name
|
|
|
|
|
|
|
|
command-init)
|
|
|
|
|
|
|
|
|
|
|
|
'error-fake-file-exists
|
|
|
|
'error-something-exists
|
|
|
|
(format (string-append "Error: The directory '~a' exists." newline
|
|
|
|
(format "Error: It looks like ~a already exists." program-path)
|
|
|
|
"Try moving, renaming, or deleting this directory.")
|
|
|
|
|
|
|
|
program-path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'error-file-doesnt-exist
|
|
|
|
'error-file-doesnt-exist
|
|
|
|
(format (string-append "Error: '~a' doesn't exist." newline
|
|
|
|
(format (string-append "Error: '~a' doesn't exist." newline
|
|
|
|
"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."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'error-not-an-option
|
|
|
|
|
|
|
|
"Error: not an option."
|
|
|
|
|
|
|
|
|
|
|
|
'warning-permissions
|
|
|
|
'error-not-a-number
|
|
|
|
(format (string-append "Warning: The permissions on your '~a' file are incorrect." newline
|
|
|
|
"Error: not a number."
|
|
|
|
"Other users on this host may be able to read your file." newline
|
|
|
|
|
|
|
|
"Try running 'chmod 600 ~a' to fix this." newline)
|
|
|
|
|
|
|
|
program-path
|
|
|
|
|
|
|
|
program-path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'init-cancelled
|
|
|
|
'warning-permissions
|
|
|
|
(format "Cancelled the creation of '~a'." program-path)
|
|
|
|
(format (string-append "Warning: The permissions on your '~a' file are incorrect." newline
|
|
|
|
|
|
|
|
"Other users on this host may be able to read your file." newline
|
|
|
|
|
|
|
|
"Try running 'chmod 600 ~a' to fix this." newline)
|
|
|
|
|
|
|
|
program-path
|
|
|
|
|
|
|
|
program-path)
|
|
|
|
|
|
|
|
|
|
|
|
'init-prompt
|
|
|
|
'init-cancelled
|
|
|
|
(format (string-append "~a will create '~a'." newline
|
|
|
|
(format "Cancelled the creation of '~a'." program-path)
|
|
|
|
"Is this okay? [y/n]")
|
|
|
|
|
|
|
|
program-name
|
|
|
|
|
|
|
|
program-path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'file-created
|
|
|
|
'init-prompt
|
|
|
|
(format "Successfully created ~a." program-path)
|
|
|
|
(format (string-append "The file '~a' will be created." newline
|
|
|
|
|
|
|
|
"Is this okay? [y/n]")
|
|
|
|
|
|
|
|
program-path)
|
|
|
|
|
|
|
|
|
|
|
|
'empty-list
|
|
|
|
'file-created
|
|
|
|
"There is nothing in your list."))
|
|
|
|
(format "Successfully created ~a." program-path)
|
|
|
|
|
|
|
|
|
|
|
|
(define formatees
|
|
|
|
'empty-list
|
|
|
|
(hash
|
|
|
|
"There is nothing in your list."
|
|
|
|
'error-not-an-option
|
|
|
|
|
|
|
|
(string-append "Error: '~a' is not an option." newline
|
|
|
|
|
|
|
|
"Please choose 'y' or 'n'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'error-not-a-number
|
|
|
|
'added
|
|
|
|
(string-append "Error: '~a' is not a number.")
|
|
|
|
"Added '~a' to your list."
|
|
|
|
|
|
|
|
|
|
|
|
'added
|
|
|
|
'removed
|
|
|
|
"Added '~a' to your list."
|
|
|
|
"Removed '~a' from your list."))
|
|
|
|
|
|
|
|
|
|
|
|
'removed
|
|
|
|
|
|
|
|
"Removed '~a' from your list."))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; helpers
|
|
|
|
;; helpers
|
|
|
@ -101,177 +100,122 @@
|
|
|
|
(define (messages-ref key)
|
|
|
|
(define (messages-ref key)
|
|
|
|
(hash-ref messages key))
|
|
|
|
(hash-ref messages key))
|
|
|
|
|
|
|
|
|
|
|
|
(define (formatees-ref key)
|
|
|
|
|
|
|
|
(hash-ref formatees key))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (displayln-messages-ref key)
|
|
|
|
(define (displayln-messages-ref key)
|
|
|
|
(let ([message (messages-ref key)])
|
|
|
|
(displayln (messages-ref key)))
|
|
|
|
(displayln message)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (displayln-formatees-ref key string)
|
|
|
|
(define (displayln-format-messages-ref key value)
|
|
|
|
(let* ([formatee (formatees-ref key)]
|
|
|
|
(displayln (format (messages-ref key) value)))
|
|
|
|
[formatee-formatted (format formatee string)])
|
|
|
|
|
|
|
|
(displayln formatee-formatted)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (create-file string)
|
|
|
|
(define (create-file string)
|
|
|
|
(close-output-port
|
|
|
|
(close-output-port (open-output-file string)))
|
|
|
|
(open-output-file string)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (has-program-permissions? string)
|
|
|
|
|
|
|
|
(equal? program-permissions (file-or-directory-permissions string 'bits)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
|
|
|
|
;; Check conditions
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
|
|
|
|
(define (check-conditions)
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
[(directory-exists? program-path)
|
|
|
|
|
|
|
|
(begin (displayln-messages-ref 'error-fake-file-exists)
|
|
|
|
|
|
|
|
(exit))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[(not (file-exists? program-path))
|
|
|
|
|
|
|
|
(begin (displayln-messages-ref 'error-file-doesnt-exist)
|
|
|
|
|
|
|
|
(exit))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[(not (has-program-permissions? program-path))
|
|
|
|
|
|
|
|
(displayln-messages-ref 'warning-permissions)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[else 'do-nothing]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (has-read-permissions? string)
|
|
|
|
|
|
|
|
(equal? read-permissions (file-or-directory-permissions string 'bits)))
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; init
|
|
|
|
;; init
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (init/create-file)
|
|
|
|
|
|
|
|
(create-file program-path)
|
|
|
|
|
|
|
|
(file-or-directory-permissions program-path
|
|
|
|
|
|
|
|
program-permissions)
|
|
|
|
|
|
|
|
(displayln-messages-ref 'file-created))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (init/cancel)
|
|
|
|
(define (init/cancel)
|
|
|
|
(displayln-messages-ref 'init-cancelled)
|
|
|
|
(displayln-messages-ref 'init-cancelled)
|
|
|
|
(exit))
|
|
|
|
(exit))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (init/create-file)
|
|
|
|
|
|
|
|
(create-file program-path)
|
|
|
|
|
|
|
|
(file-or-directory-permissions program-path read-permissions)
|
|
|
|
|
|
|
|
(displayln-messages-ref 'file-created))
|
|
|
|
|
|
|
|
|
|
|
|
(define (init/prompt)
|
|
|
|
(define (init/prompt)
|
|
|
|
(displayln-messages-ref 'init-prompt)
|
|
|
|
(displayln-messages-ref 'init-prompt)
|
|
|
|
(display "> ")
|
|
|
|
(display "> ")
|
|
|
|
(let* ([input (read-line)]
|
|
|
|
(let ([input-symbol (string->symbol (read-line))])
|
|
|
|
[input-symbol (string->symbol input)])
|
|
|
|
|
|
|
|
(case input-symbol
|
|
|
|
(case input-symbol
|
|
|
|
['y (init/create-file)]
|
|
|
|
['y (init/create-file)]
|
|
|
|
['n (init/cancel)]
|
|
|
|
['n (init/cancel)]
|
|
|
|
[else (displayln-formatees-ref 'error-not-an-option input)])))
|
|
|
|
[else (displayln-messages-ref 'error-not-an-option)])))
|
|
|
|
|
|
|
|
|
|
|
|
(define (init)
|
|
|
|
(define (init)
|
|
|
|
(cond
|
|
|
|
(if (or (file-exists? program-path)
|
|
|
|
[(file-exists? program-path)
|
|
|
|
(directory-exists? program-path))
|
|
|
|
(displayln-messages-ref 'error-file-already-exists)]
|
|
|
|
(displayln-messages-ref 'error-something-exists)
|
|
|
|
|
|
|
|
(init/prompt)))
|
|
|
|
[(directory-exists? program-path)
|
|
|
|
|
|
|
|
(displayln-messages-ref 'error-fake-file-exists)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[else (init/prompt)]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ls
|
|
|
|
;; ls
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (ls/display-list listof-items)
|
|
|
|
(define (ls/display-list listof-items)
|
|
|
|
;; The add1 in the first binding starts the
|
|
|
|
(let* ([listof-number-strings (map number->string (range (length listof-items)))]
|
|
|
|
;; listof-numbers at 1 instead of 0 to make the
|
|
|
|
[listof-numbered-items (map (lambda (a b) (string-append a ". " b))
|
|
|
|
;; list numbering more human-friendly
|
|
|
|
|
|
|
|
(let* ([listof-numbers (map add1 (range (length listof-items)))]
|
|
|
|
|
|
|
|
[listof-number-strings (map number->string listof-numbers)]
|
|
|
|
|
|
|
|
[combine-lists (lambda (a b) (string-append a ". " b))]
|
|
|
|
|
|
|
|
[listof-numbered-items (map combine-lists
|
|
|
|
|
|
|
|
listof-number-strings
|
|
|
|
listof-number-strings
|
|
|
|
listof-items)])
|
|
|
|
listof-items)])
|
|
|
|
(for ([item listof-numbered-items])
|
|
|
|
(for ([item listof-numbered-items])
|
|
|
|
(displayln item))))
|
|
|
|
(displayln item))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (ls)
|
|
|
|
(define (ls)
|
|
|
|
(check-conditions)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
(if (null? listof-items)
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
|
|
|
|
(if (null? listof-items)
|
|
|
|
(displayln-messages-ref 'empty-list)
|
|
|
|
(displayln-messages-ref 'empty-list)
|
|
|
|
(ls/display-list listof-items))))
|
|
|
|
(ls/display-list listof-items)))
|
|
|
|
|
|
|
|
(displayln-messages-ref 'couldnt-file-file)))
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; rm
|
|
|
|
;; rm
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (rm/remove-item listof-items item-number)
|
|
|
|
(define (rm/remove-nicething item-number)
|
|
|
|
(let* ([item-to-remove (list-ref listof-items item-number)]
|
|
|
|
(let ([listof-items (file->lines program-path)])
|
|
|
|
[list-without-item (remove item-to-remove listof-items)])
|
|
|
|
|
|
|
|
(display-lines-to-file list-without-item
|
|
|
|
|
|
|
|
program-path
|
|
|
|
|
|
|
|
#:exists 'truncate)
|
|
|
|
|
|
|
|
(displayln-formatees-ref 'removed item-to-remove)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (rm/process-string string)
|
|
|
|
|
|
|
|
(let* ([listof-items (file->lines program-path)]
|
|
|
|
|
|
|
|
[item-number (string->number string)]
|
|
|
|
|
|
|
|
;; Subtract 1 from the user's original number,
|
|
|
|
|
|
|
|
;; because we want to convert the number from
|
|
|
|
|
|
|
|
;; human numbers (1 2 3) to index numbers
|
|
|
|
|
|
|
|
;; (0 1 2)
|
|
|
|
|
|
|
|
[item-number-sub1 (sub1 item-number)]
|
|
|
|
|
|
|
|
[list-length (length listof-items)])
|
|
|
|
|
|
|
|
(if (and (not (null? listof-items))
|
|
|
|
(if (and (not (null? listof-items))
|
|
|
|
(number? item-number)
|
|
|
|
(exact? item-number)
|
|
|
|
(positive? item-number)
|
|
|
|
(>= item-number 0)
|
|
|
|
;; Don't allow numbers that are equal to
|
|
|
|
(< item-number (length listof-items)))
|
|
|
|
;; or greater than list-length, because
|
|
|
|
(let* ([item-to-remove (list-ref listof-items item-number)]
|
|
|
|
;; the list index starts at 0
|
|
|
|
[list-without-item (remove item-to-remove listof-items)])
|
|
|
|
;;
|
|
|
|
(display-lines-to-file list-without-item program-path #:exists 'truncate)
|
|
|
|
;; Example:
|
|
|
|
(displayln-format-messages-ref 'removed item-to-remove))
|
|
|
|
;; Length of (1 2 3) = 3
|
|
|
|
(displayln-messages-ref 'error-item-not-found))))
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; To reference the highest number, we
|
|
|
|
|
|
|
|
;; use (list-ref (1 2 3) 2)
|
|
|
|
|
|
|
|
(< item-number-sub1 list-length))
|
|
|
|
|
|
|
|
(rm/remove-item listof-items item-number-sub1)
|
|
|
|
|
|
|
|
(displayln-messages-ref 'error-item-not-found))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (rm string)
|
|
|
|
(define (rm arg)
|
|
|
|
(check-conditions)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
(if (string->number string)
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
(rm/process-string string)
|
|
|
|
(let ([item-number (string->number arg)])
|
|
|
|
(displayln-formatees-ref 'error-not-a-number string)))
|
|
|
|
(if item-number
|
|
|
|
|
|
|
|
(rm/remove-nicething item-number)
|
|
|
|
|
|
|
|
(displayln-format-messages-ref 'error-not-a-number arg)))
|
|
|
|
|
|
|
|
(displayln-messages-ref 'couldnt-find-file)))
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; add
|
|
|
|
;; add
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (add string)
|
|
|
|
(define (add nicething)
|
|
|
|
(check-conditions)
|
|
|
|
(if (and (file-exists? program-path)
|
|
|
|
;; The removing and adding of the '\n' is to
|
|
|
|
(has-read-permissions? program-path))
|
|
|
|
;; ensure only one '\n' exists at the end of the
|
|
|
|
;; The removing and adding of the '\n' is to
|
|
|
|
;; item to be added.
|
|
|
|
;; ensure only one '\n' exists at the end of the
|
|
|
|
(let* ([string-no-newline (string-replace string "\n" "")]
|
|
|
|
;; item to be added.
|
|
|
|
[string-newline (string-append string-no-newline "\n")])
|
|
|
|
(let* ([nicething-no-newline (string-replace nicething "\n" "")]
|
|
|
|
(display-to-file string-newline
|
|
|
|
[nicething-newline (string-append nicething-no-newline "\n")])
|
|
|
|
program-path
|
|
|
|
(display-to-file nicething-newline program-path #:exists 'append)
|
|
|
|
#:exists 'append)
|
|
|
|
(displayln-format-messages-ref 'added nicething-no-newline))
|
|
|
|
(displayln-formatees-ref 'added string-no-newline)))
|
|
|
|
(displayln-messages-ref 'couldnt-find-file)))
|
|
|
|
|
|
|
|
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; random message
|
|
|
|
;; random message
|
|
|
|
;; ------------------------------------------------
|
|
|
|
;; ------------------------------------------------
|
|
|
|
(define (random-message/append-program-file home-directory)
|
|
|
|
|
|
|
|
(build-path home-directory program-file))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (random-message)
|
|
|
|
(define (random-message)
|
|
|
|
(let* ([root (find-system-path 'sys-dir)] ;; /
|
|
|
|
(let* ([root-home (build-path (find-system-path 'sys-dir) "home")] ;; /home
|
|
|
|
[root-home (build-path root "home")] ;; /home
|
|
|
|
|
|
|
|
;; `#:build? #t` Builds full paths for all items listed in /home/
|
|
|
|
;; `#:build? #t` Builds full paths for all items listed in /home/
|
|
|
|
[listof-home-directories (directory-list root-home #:build? #t)]
|
|
|
|
[listof-home-directories (directory-list root-home #:build? #t)]
|
|
|
|
[listof-nicethings-paths (map random-message/append-program-file listof-home-directories)]
|
|
|
|
[listof-nicethings-paths (map (lambda (x) (build-path x program-file))
|
|
|
|
[directories-with-nicethings (filter file-exists? listof-nicethings-paths)]
|
|
|
|
listof-home-directories)]
|
|
|
|
[directories-with-644 (filter has-program-permissions? directories-with-nicethings)]
|
|
|
|
[paths-with-nicethings (filter file-exists? listof-nicethings-paths)]
|
|
|
|
[listof-nicethings (apply append (map file->lines directories-with-644))]
|
|
|
|
[paths-readable (filter has-read-permissions? paths-with-nicethings)]
|
|
|
|
[list-length (length listof-nicethings)])
|
|
|
|
[listof-nicethings (apply append (map file->lines paths-readable))]
|
|
|
|
|
|
|
|
[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
|
|
|
@ -279,36 +223,36 @@
|
|
|
|
(define (help)
|
|
|
|
(define (help)
|
|
|
|
(displayln
|
|
|
|
(displayln
|
|
|
|
(string-append
|
|
|
|
(string-append
|
|
|
|
"Usage:" newline
|
|
|
|
"Usage:" newline
|
|
|
|
(format " ~a [<command>] [<args>]" program-name)
|
|
|
|
(format " ~a [<command>] [<args>]" program-name)
|
|
|
|
double-newline
|
|
|
|
double-newline
|
|
|
|
|
|
|
|
|
|
|
|
"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)]))
|
|
|
|
|
|
|
|
|
|
|
|