2018-03-12 14:02:54 +00:00
|
|
|
#! /usr/bin/env racket
|
|
|
|
#lang racket/base
|
|
|
|
|
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-03-16 13:53:12 +00:00
|
|
|
(define messages (hash
|
2018-03-17 02:53:59 +00:00
|
|
|
'incorrect-usage "> For usage type `rodo -h` or `rodo --help`"
|
|
|
|
'file-not-found "> rodo has not been setup in your home directory\nWould you like to set it up now? [y/n]"
|
|
|
|
'file-exists "> .rodo file exists"
|
2018-03-16 13:53:12 +00:00
|
|
|
'creating-file "> Creating .rodo file in your home directory..."
|
2018-03-17 02:53:59 +00:00
|
|
|
'item-added "> Item added"
|
|
|
|
'item-removed "> Item removed"
|
|
|
|
'initializing "> Initializing rodo in your home directory"
|
|
|
|
'terminating "> Terminating rodo..."
|
|
|
|
'choose-y/n "> Error: Please choose y or n"))
|
2018-03-12 14:02:54 +00:00
|
|
|
|
2018-03-16 13:53:12 +00:00
|
|
|
(define y/n (hash
|
|
|
|
'yes '("yes" "Yes" "y" "Y")
|
|
|
|
'no '("no" "No" "n" "N")))
|
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-14 14:45:05 +00:00
|
|
|
#:mode 'text
|
2018-03-19 20:56:52 +00:00
|
|
|
#:exists 'can-update)])
|
|
|
|
(close-output-port opened-file))))
|
2018-03-13 16:39:10 +00:00
|
|
|
|
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-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-14 14:45:05 +00:00
|
|
|
(open/create-file "~/.rodo")]
|
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-03-12 14:02:54 +00:00
|
|
|
(define (todo-list-exist?)
|
|
|
|
(if (file-exists? (expand-user-path "~/.rodo"))
|
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-03-17 14:44:22 +00:00
|
|
|
(todo-list-exist?)
|