I don't remmeber what I fixed. It's late
parent
ed5541ba9a
commit
d769db8737
75
rodo.rkt
75
rodo.rkt
|
@ -1,12 +1,14 @@
|
||||||
#! /usr/bin/env racket
|
#! /usr/bin/env racket
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/vector racket/file)
|
(require racket/vector
|
||||||
|
racket/file)
|
||||||
|
|
||||||
(define program-name "rodo")
|
(define program-name "rodo")
|
||||||
(define program-directory ".rodo/")
|
(define program-directory ".rodo/")
|
||||||
(define program-path "~/")
|
(define program-path "~/")
|
||||||
(define program-file "todo-list")
|
(define program-file "todo-list")
|
||||||
|
(define bullet "*")
|
||||||
|
|
||||||
(define (d-hash-ref hash-list key)
|
(define (d-hash-ref hash-list key)
|
||||||
(display (hash-ref hash-list key)))
|
(display (hash-ref hash-list key)))
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
|
|
||||||
(define messages
|
(define messages
|
||||||
(hash
|
(hash
|
||||||
'incorrect-usage
|
'show-usage
|
||||||
(string-append
|
(string-append
|
||||||
"> For usage type "
|
"> For usage type "
|
||||||
"`" program-name " -h`"
|
"`" program-name " -h`"
|
||||||
|
@ -41,17 +43,20 @@
|
||||||
'creation-error
|
'creation-error
|
||||||
(string-append
|
(string-append
|
||||||
"> Error: Could not create "
|
"> Error: Could not create "
|
||||||
program-directory
|
program-file
|
||||||
" in "
|
" in "
|
||||||
|
program-directory
|
||||||
program-path ".\n"
|
program-path ".\n"
|
||||||
"> This may be due to directory permissions\n")
|
"> This may be due to directory permissions\n")
|
||||||
|
|
||||||
'already-exists
|
'file-already-exists
|
||||||
(string-append
|
(string-append
|
||||||
"> "
|
"> Error: "
|
||||||
|
program-name
|
||||||
|
" already exists in "
|
||||||
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
" folder already exists in "
|
program-file "\n")
|
||||||
program-path "\n")
|
|
||||||
|
|
||||||
'successfully-created
|
'successfully-created
|
||||||
(string-append
|
(string-append
|
||||||
|
@ -61,22 +66,26 @@
|
||||||
program-file
|
program-file
|
||||||
" has been successfully created\n")
|
" has been successfully created\n")
|
||||||
|
|
||||||
'not-found
|
'file-not-found
|
||||||
(string-append
|
(string-append
|
||||||
"> "
|
"> Error: Could not find "
|
||||||
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
" has not been setup in "
|
program-file "\n")
|
||||||
program-path "\n")
|
|
||||||
|
|
||||||
'setup-y/n
|
'init-y/n
|
||||||
(string-append
|
(string-append
|
||||||
"> Would you like to set it up now? [y/n]\n")
|
"> A "
|
||||||
|
program-file
|
||||||
|
" file will be created in "
|
||||||
|
program-path
|
||||||
|
program-directory "\n"
|
||||||
|
"> Are you sure you want to continue? [y/n]\n")
|
||||||
|
|
||||||
'try-initializing
|
'try-init
|
||||||
(string-append
|
(string-append
|
||||||
"> Try typing "
|
"> Try typing "
|
||||||
"`" program-name
|
"`" program-name " init` "
|
||||||
" init` "
|
|
||||||
"to set it up\n")
|
"to set it up\n")
|
||||||
|
|
||||||
'terminating
|
'terminating
|
||||||
|
@ -109,7 +118,7 @@
|
||||||
'("no" "No" "n" "N")))
|
'("no" "No" "n" "N")))
|
||||||
|
|
||||||
(define (add-item-to-file item)
|
(define (add-item-to-file item)
|
||||||
(let ([item (string-append item "\n")])
|
(let ([item (string-append bullet " " item "\n")])
|
||||||
(let
|
(let
|
||||||
([path
|
([path
|
||||||
(expand-user-path
|
(expand-user-path
|
||||||
|
@ -118,9 +127,9 @@
|
||||||
program-directory
|
program-directory
|
||||||
program-file))])
|
program-file))])
|
||||||
(display-to-file item
|
(display-to-file item
|
||||||
path
|
path
|
||||||
#:mode 'text
|
#:mode 'text
|
||||||
#:exists 'append))))
|
#:exists 'append))))
|
||||||
|
|
||||||
(define (create-file)
|
(define (create-file)
|
||||||
(let
|
(let
|
||||||
|
@ -159,7 +168,7 @@
|
||||||
program-path
|
program-path
|
||||||
program-directory))))
|
program-directory))))
|
||||||
|
|
||||||
(define (prompt-user hash-list key)
|
(define (prompt-user-init hash-list key)
|
||||||
(d-hash-ref hash-list key)
|
(d-hash-ref hash-list key)
|
||||||
(display "> ")
|
(display "> ")
|
||||||
(let
|
(let
|
||||||
|
@ -181,7 +190,7 @@
|
||||||
(d-hash-ref messages 'terminating)]
|
(d-hash-ref messages 'terminating)]
|
||||||
|
|
||||||
[else
|
[else
|
||||||
(prompt-user messages 'choose-y/n)])))
|
(prompt-user-init messages 'choose-y/n)])))
|
||||||
|
|
||||||
(define (add-item args)
|
(define (add-item args)
|
||||||
(if
|
(if
|
||||||
|
@ -194,8 +203,8 @@
|
||||||
(d-vector-ref args 1)
|
(d-vector-ref args 1)
|
||||||
(d-hash-ref messages 'item-added-suffix))
|
(d-hash-ref messages 'item-added-suffix))
|
||||||
(begin
|
(begin
|
||||||
(d-hash-ref messages 'not-found)
|
(d-hash-ref messages 'file-not-found)
|
||||||
(d-hash-ref messages 'try-initializing))))
|
(d-hash-ref messages 'try-init))))
|
||||||
|
|
||||||
(define (remove-item args)
|
(define (remove-item args)
|
||||||
(if
|
(if
|
||||||
|
@ -203,12 +212,13 @@
|
||||||
(check-for-folder)
|
(check-for-folder)
|
||||||
(check-for-file))
|
(check-for-file))
|
||||||
(begin
|
(begin
|
||||||
|
;; TODO (remove-item-from-file (vector-ref args 1))
|
||||||
(d-hash-ref messages 'item-removed-prefix)
|
(d-hash-ref messages 'item-removed-prefix)
|
||||||
(d-vector-ref args 1)
|
(d-vector-ref args 1)
|
||||||
(d-hash-ref messages 'item-removed-suffix))
|
(d-hash-ref messages 'item-removed-suffix))
|
||||||
(begin
|
(begin
|
||||||
(d-hash-ref messages 'not-found)
|
(d-hash-ref messages 'file-not-found)
|
||||||
(d-hash-ref messages 'try-initializing))))
|
(d-hash-ref messages 'try-init))))
|
||||||
|
|
||||||
(define (check-args args)
|
(define (check-args args)
|
||||||
(let
|
(let
|
||||||
|
@ -227,17 +237,16 @@
|
||||||
[(and
|
[(and
|
||||||
(equal? args-length 1)
|
(equal? args-length 1)
|
||||||
(equal? (vector-member "init" args) 0))
|
(equal? (vector-member "init" args) 0))
|
||||||
(todo-already-exists?)]
|
(initialize)]
|
||||||
|
|
||||||
[else
|
[else
|
||||||
(d-hash-ref messages 'incorrect-usage)])))
|
(d-hash-ref messages 'show-usage)])))
|
||||||
|
|
||||||
(define (todo-already-exists?)
|
(define (initialize)
|
||||||
(if (check-for-folder)
|
(if (check-for-file)
|
||||||
(d-hash-ref messages 'already-exists)
|
(d-hash-ref messages 'file-already-exists)
|
||||||
(begin
|
(begin
|
||||||
(d-hash-ref messages 'not-found)
|
(prompt-user-init messages 'init-y/n))))
|
||||||
(prompt-user messages 'setup-y/n))))
|
|
||||||
|
|
||||||
(define (main)
|
(define (main)
|
||||||
(check-args (current-command-line-arguments)))
|
(check-args (current-command-line-arguments)))
|
||||||
|
|
Loading…
Reference in New Issue