fixed a little bug where if you first initialized and then tried to remove something from an empty file it would produce an error
parent
711cd96ddb
commit
88f4480f3a
3
io.rkt
3
io.rkt
|
@ -1,6 +1,7 @@
|
|||
#lang racket/base
|
||||
|
||||
(require "config.rkt")
|
||||
(require racket/file
|
||||
"config.rkt")
|
||||
|
||||
(provide (all-defined-out))
|
||||
|
||||
|
|
|
@ -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 "
|
||||
|
||||
|
|
29
util.rkt
29
util.rkt
|
@ -100,12 +100,23 @@
|
|||
#:exists 'replace))))
|
||||
|
||||
(define (remove-item args)
|
||||
(if
|
||||
(and
|
||||
(number? (string->number (vector-ref args 1)))
|
||||
(check-for-folder)
|
||||
(check-for-file))
|
||||
(remove-item-from-file (vector-ref args 1))
|
||||
(begin
|
||||
(d-hash-ref messages 'file-not-found)
|
||||
(d-hash-ref messages 'try-init))))
|
||||
(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))]
|
||||
[(and (not (check-for-folder)) (not (check-for-file)))
|
||||
(begin
|
||||
(d-hash-ref messages 'file-not-found)
|
||||
(d-hash-ref messages 'try-init))]
|
||||
[(>= (string->number (vector-ref args 1)) (vector-length args))
|
||||
(d-hash-ref messages 'not-in-list)])))
|
||||
|
|
Loading…
Reference in New Issue