getting rid of hardcoded paths and names
parent
35f28df5d3
commit
f0222bb755
27
rodo.rkt
27
rodo.rkt
|
@ -1,21 +1,27 @@
|
||||||
#! /usr/bin/env racket
|
#! /usr/bin/env racket
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
|
(define program-name "rodo")
|
||||||
|
|
||||||
|
(define program-path "~/.")
|
||||||
|
|
||||||
(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 messages (hash
|
(define messages
|
||||||
'incorrect-usage "> For usage type `rodo -h` or `rodo --help`"
|
(hash
|
||||||
'file-not-found "> rodo has not been setup in your home directory\nWould you like to set it up now? [y/n]"
|
'incorrect-usage (string-append "> For usage type `" program-name " -h` or `" program-name " --help`")
|
||||||
'file-exists "> .rodo file exists"
|
'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]")
|
||||||
'creating-file "> Creating .rodo file in your home directory..."
|
'file-exists (string-append "> ." program-name " file exists")
|
||||||
|
'creating-file (string-append "> Creating ." program-name " file in your home directory...")
|
||||||
'item-added "> Item added"
|
'item-added "> Item added"
|
||||||
'item-removed "> Item removed"
|
'item-removed "> Item removed"
|
||||||
'initializing "> Initializing rodo in your home directory"
|
'initializing (string-append "> Initializing " program-name " in your home directory")
|
||||||
'terminating "> Terminating rodo..."
|
'terminating (string-append "> Terminating " program-name "...")
|
||||||
'choose-y/n "> Error: Please choose y or n"))
|
'choose-y/n "> Error: Please choose y or n"))
|
||||||
|
|
||||||
(define y/n (hash
|
(define y/n
|
||||||
|
(hash
|
||||||
'yes '("yes" "Yes" "y" "Y")
|
'yes '("yes" "Yes" "y" "Y")
|
||||||
'no '("no" "No" "n" "N")))
|
'no '("no" "No" "n" "N")))
|
||||||
|
|
||||||
|
@ -28,11 +34,12 @@
|
||||||
|
|
||||||
(define (prompt-user prompt-message)
|
(define (prompt-user prompt-message)
|
||||||
(displayln-hash-ref messages prompt-message)
|
(displayln-hash-ref messages prompt-message)
|
||||||
|
(display "> ")
|
||||||
(let ([user-input (read-line)])
|
(let ([user-input (read-line)])
|
||||||
(cond
|
(cond
|
||||||
[(member user-input (hash-ref y/n 'yes))
|
[(member user-input (hash-ref y/n 'yes))
|
||||||
(displayln-hash-ref messages 'creating-file)
|
(displayln-hash-ref messages 'creating-file)
|
||||||
(open/create-file "~/.rodo")]
|
(open/create-file (string-append program-path program-name))]
|
||||||
[(member user-input (hash-ref y/n 'no))
|
[(member user-input (hash-ref y/n 'no))
|
||||||
(displayln-hash-ref messages 'terminating)]
|
(displayln-hash-ref messages 'terminating)]
|
||||||
[else
|
[else
|
||||||
|
@ -40,7 +47,7 @@
|
||||||
(prompt-user 'file-not-found)])))
|
(prompt-user 'file-not-found)])))
|
||||||
|
|
||||||
(define (todo-list-exist?)
|
(define (todo-list-exist?)
|
||||||
(if (file-exists? (expand-user-path "~/.rodo"))
|
(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-user 'file-not-found)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue