too many things added

main
m455 2018-04-02 13:51:08 -04:00
parent 27bfaaee40
commit 5eceb71e2c
1 changed files with 26 additions and 24 deletions

View File

@ -1,6 +1,6 @@
#! /usr/bin/env racket #! /usr/bin/env racket
#lang racket/base #lang racket/base
(require json) (require json racket/vector)
;; set the name of the program here ;; set the name of the program here
(define program-name "rodo") (define program-name "rodo")
@ -12,6 +12,14 @@
(define (displayln-hash-ref hash-list key) (define (displayln-hash-ref hash-list key)
(displayln (hash-ref hash-list key))) (displayln (hash-ref hash-list key)))
;; (define (add-to-list)
;; (let ([args (vector-ref (current-command-line-arguments) 1)])
;; (string-append "> Added " args " to list")))
;;(define (remove-from-list)
;; (let ([args (vector-ref (current-command-line-arguments) 1)])
;; (string-append "> Removed " args " from list")))
;; define all messages for quick access ;; define all messages for quick access
(define messages (define messages
(hash (hash
@ -20,12 +28,9 @@
'file-exists (string-append "> ." program-name " file exists") 'file-exists (string-append "> ." program-name " file exists")
'creating-file (string-append "> Creating ." program-name " file in your home directory...") 'creating-file (string-append "> Creating ." program-name " file in your home directory...")
;; temporary thing 'item-added "> Added item to list"
'item-added (string-append "> Added ") 'item-removed "> Added item to list"
;; todo change `item` to command-line argument for add and remove
;; 'item-added (string-append "> Added " (vector-ref (current-command-line-arguments) 1))
;; 'item-removed "> Item removed" ;; todo change `item` to command-line argument
'initializing (string-append "> Initializing " program-name " in your home directory") 'initializing (string-append "> Initializing " program-name " in your home directory")
'terminating (string-append "> Exiting " program-name "...") 'terminating (string-append "> Exiting " program-name "...")
'choose-y/n "> Error: Please choose y or n")) 'choose-y/n "> Error: Please choose y or n"))
@ -45,7 +50,7 @@
(close-output-port opened-file)))) (close-output-port opened-file))))
;; talk with user if something goes wrong/right ;; talk with user if something goes wrong/right
(define (prompt-user prompt-message) (define (prompt-initialize prompt-message)
(displayln-hash-ref messages prompt-message) (displayln-hash-ref messages prompt-message)
(display "> ") (display "> ")
(let ([user-input (read-line)]) (let ([user-input (read-line)])
@ -57,27 +62,24 @@
(displayln-hash-ref messages 'terminating)] (displayln-hash-ref messages 'terminating)]
[else [else
(displayln-hash-ref messages 'choose-y/n) (displayln-hash-ref messages 'choose-y/n)
(prompt-user 'file-not-found)]))) (prompt-initialize 'file-not-found)])))
(define (add-to-list args)
;; (let ([item (vector-ref args 1)])
(displayln-hash-ref messages 'item-added))
(define (check-args args) (define (check-args args)
(vector-length (args))) (let ([args-length (vector-length args)])
(cond
[(or (equal? args-length 0) (> args-length 2))
(displayln-hash-ref messages 'incorrect-usage)]
[(and (equal? args-length 2) (equal? (vector-member "add" args) 0))
(displayln-hash-ref messages 'item-added)]
[(and (equal? args-length 1) (equal? (vector-member "init" args) 0))
(todo-list-exist?)])))
(define (todo-list-exist?) (define (todo-list-exist?)
(if (file-exists? (expand-user-path (string-append program-path program-name))) (if (file-exists? (expand-user-path (string-append program-path program-name)))
(displayln-hash-ref messages 'file-exists) (displayln-hash-ref messages 'file-exists)
(prompt-user 'file-not-found))) (prompt-initialize 'file-not-found)))
;; todo get command-line args (define (main)
#|(define (todo-list-exist?) (check-args (current-command-line-arguments)))
(if (file-exists? (expand-user-path (string-append program-path program-name)))
(begin
(displayln-hash-ref messages 'file-exists)
(add-to-list (current-command-line-arguments)))
(prompt-user 'file-not-found)))
|#
(todo-list-exist?) (main)