2018-03-12 14:02:54 +00:00
|
|
|
#! /usr/bin/env racket
|
|
|
|
#lang racket/base
|
2018-04-02 15:37:33 +00:00
|
|
|
(require json)
|
2018-03-12 14:02:54 +00:00
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; set the name of the program here
|
2018-03-26 17:43:17 +00:00
|
|
|
(define program-name "rodo")
|
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; set which path the program will live in
|
2018-03-26 17:43:17 +00:00
|
|
|
(define program-path "~/.")
|
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; because I don't want to type `(display (hash-ref...` over and over again
|
2018-03-19 20:56:52 +00:00
|
|
|
(define (displayln-hash-ref hash-list key)
|
2018-03-13 02:19:16 +00:00
|
|
|
(displayln (hash-ref hash-list key)))
|
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; define all messages for quick access
|
2018-03-26 17:43:17 +00:00
|
|
|
(define messages
|
|
|
|
(hash
|
|
|
|
'incorrect-usage (string-append "> For usage type `" program-name " -h` or `" program-name " --help`")
|
|
|
|
'file-not-found (string-append "> " program-name " has not been setup in your home directory\n> Would you like to set it up now? [y/n]")
|
|
|
|
'file-exists (string-append "> ." program-name " file exists")
|
|
|
|
'creating-file (string-append "> Creating ." program-name " file in your home directory...")
|
2018-04-02 15:37:33 +00:00
|
|
|
|
|
|
|
;; temporary thing
|
|
|
|
'item-added (string-append "> Added ")
|
|
|
|
|
|
|
|
;; 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
|
2018-03-26 17:43:17 +00:00
|
|
|
'initializing (string-append "> Initializing " program-name " in your home directory")
|
2018-04-02 15:37:33 +00:00
|
|
|
'terminating (string-append "> Exiting " program-name "...")
|
2018-03-26 17:43:17 +00:00
|
|
|
'choose-y/n "> Error: Please choose y or n"))
|
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; some possible user-input related "mistakes" that will be accepted for input
|
2018-03-26 17:43:17 +00:00
|
|
|
(define y/n
|
|
|
|
(hash
|
|
|
|
'yes '("yes" "Yes" "y" "Y")
|
|
|
|
'no '("no" "No" "n" "N")))
|
2018-03-14 14:45:05 +00:00
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; yet again, less typing for opening a file
|
2018-03-14 14:45:05 +00:00
|
|
|
(define (open/create-file path)
|
|
|
|
(let ([path (expand-user-path path)])
|
2018-03-19 20:56:52 +00:00
|
|
|
(let ([opened-file (open-output-file path
|
2018-03-26 17:43:17 +00:00
|
|
|
#:mode 'text
|
|
|
|
#:exists 'can-update)])
|
2018-03-19 20:56:52 +00:00
|
|
|
(close-output-port opened-file))))
|
2018-03-13 16:39:10 +00:00
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; talk with user if something goes wrong/right
|
2018-03-13 02:19:16 +00:00
|
|
|
(define (prompt-user prompt-message)
|
2018-03-19 20:56:52 +00:00
|
|
|
(displayln-hash-ref messages prompt-message)
|
2018-03-26 17:43:17 +00:00
|
|
|
(display "> ")
|
2018-03-13 02:19:16 +00:00
|
|
|
(let ([user-input (read-line)])
|
|
|
|
(cond
|
2018-03-16 13:53:12 +00:00
|
|
|
[(member user-input (hash-ref y/n 'yes))
|
2018-03-19 20:56:52 +00:00
|
|
|
(displayln-hash-ref messages 'creating-file)
|
2018-03-26 17:43:17 +00:00
|
|
|
(open/create-file (string-append program-path program-name))]
|
2018-03-16 13:53:12 +00:00
|
|
|
[(member user-input (hash-ref y/n 'no))
|
2018-03-19 20:56:52 +00:00
|
|
|
(displayln-hash-ref messages 'terminating)]
|
2018-03-13 02:19:16 +00:00
|
|
|
[else
|
2018-03-19 20:56:52 +00:00
|
|
|
(displayln-hash-ref messages 'choose-y/n)
|
2018-03-16 13:53:12 +00:00
|
|
|
(prompt-user 'file-not-found)])))
|
2018-03-13 02:19:16 +00:00
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
(define (add-to-list args)
|
|
|
|
;; (let ([item (vector-ref args 1)])
|
|
|
|
(displayln-hash-ref messages 'item-added))
|
|
|
|
|
|
|
|
(define (check-args args)
|
|
|
|
(vector-length (args)))
|
|
|
|
|
2018-03-12 14:02:54 +00:00
|
|
|
(define (todo-list-exist?)
|
2018-03-26 17:43:17 +00:00
|
|
|
(if (file-exists? (expand-user-path (string-append program-path program-name)))
|
2018-03-19 20:56:52 +00:00
|
|
|
(displayln-hash-ref messages 'file-exists)
|
2018-03-16 13:53:12 +00:00
|
|
|
(prompt-user 'file-not-found)))
|
2018-03-12 14:02:54 +00:00
|
|
|
|
2018-04-02 15:37:33 +00:00
|
|
|
;; todo get command-line args
|
|
|
|
#|(define (todo-list-exist?)
|
|
|
|
(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)))
|
|
|
|
|#
|
|
|
|
|
2018-03-17 14:44:22 +00:00
|
|
|
(todo-list-exist?)
|