fixed a little bug where if you first initialized and then tried to remove something from an empty file it would produce an error

main
m455 2018-04-13 02:08:22 -04:00
parent 711cd96ddb
commit 88f4480f3a
3 changed files with 29 additions and 11 deletions

3
io.rkt
View File

@ -1,6 +1,7 @@
#lang racket/base
(require "config.rkt")
(require racket/file
"config.rkt")
(provide (all-defined-out))

View File

@ -40,6 +40,9 @@
"\x09Example: "
"rodo rm 1\n")
'empty-todo-list
"Error> There is nothing in your list yet\n"
'show-usage
(string-append
"> For usage type "
@ -119,6 +122,9 @@
'choose-y/n
"> Error: Please choose y or n\n"
'not-in-list
"> Error: Item does not exist\n"
'item-added-prefix
"> Added "

View File

@ -100,12 +100,23 @@
#:exists 'replace))))
(define (remove-item args)
(if
(and
(let ([todo-list
(file->lines
path
#:mode 'text
#:line-mode 'linefeed)])
(cond
[(< (length todo-list) 1)
(d-hash-ref messages 'empty-todo-list)]
[(and
(number? (string->number (vector-ref args 1)))
(< (string->number (vector-ref args 1)) (vector-length args))
(check-for-folder)
(check-for-file))
(remove-item-from-file (vector-ref args 1))
(remove-item-from-file (vector-ref args 1))]
[(and (not (check-for-folder)) (not (check-for-file)))
(begin
(d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init))))
(d-hash-ref messages 'try-init))]
[(>= (string->number (vector-ref args 1)) (vector-length args))
(d-hash-ref messages 'not-in-list)])))