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
|
#lang racket/base
|
||||||
|
|
||||||
(require "config.rkt")
|
(require racket/file
|
||||||
|
"config.rkt")
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
"\x09Example: "
|
"\x09Example: "
|
||||||
"rodo rm 1\n")
|
"rodo rm 1\n")
|
||||||
|
|
||||||
|
'empty-todo-list
|
||||||
|
"Error> There is nothing in your list yet\n"
|
||||||
|
|
||||||
'show-usage
|
'show-usage
|
||||||
(string-append
|
(string-append
|
||||||
"> For usage type "
|
"> For usage type "
|
||||||
|
@ -119,6 +122,9 @@
|
||||||
'choose-y/n
|
'choose-y/n
|
||||||
"> Error: Please choose y or n\n"
|
"> Error: Please choose y or n\n"
|
||||||
|
|
||||||
|
'not-in-list
|
||||||
|
"> Error: Item does not exist\n"
|
||||||
|
|
||||||
'item-added-prefix
|
'item-added-prefix
|
||||||
"> Added "
|
"> Added "
|
||||||
|
|
||||||
|
|
29
util.rkt
29
util.rkt
|
@ -100,12 +100,23 @@
|
||||||
#:exists 'replace))))
|
#:exists 'replace))))
|
||||||
|
|
||||||
(define (remove-item args)
|
(define (remove-item args)
|
||||||
(if
|
(let ([todo-list
|
||||||
(and
|
(file->lines
|
||||||
(number? (string->number (vector-ref args 1)))
|
path
|
||||||
(check-for-folder)
|
#:mode 'text
|
||||||
(check-for-file))
|
#:line-mode 'linefeed)])
|
||||||
(remove-item-from-file (vector-ref args 1))
|
(cond
|
||||||
(begin
|
[(< (length todo-list) 1)
|
||||||
(d-hash-ref messages 'file-not-found)
|
(d-hash-ref messages 'empty-todo-list)]
|
||||||
(d-hash-ref messages 'try-init))))
|
[(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