Add update command
* undone/main.scm (args->alist): Place argument parsing for add/update in separate function for reuse. (delete-item): Renamed from `delete', which is in conflict with guile's own `delete'. (update): New function.
This commit is contained in:
parent
5e4c1f54f4
commit
436f57cb55
1 changed files with 31 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
#:use-module (ice-9 format)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:use-module (oop goops)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (undone view)
|
||||
#:export (main))
|
||||
|
||||
|
@ -133,6 +134,16 @@
|
|||
todo-list)))
|
||||
1))
|
||||
|
||||
(define (args->alist args)
|
||||
(map (lambda (arg)
|
||||
(let* ((pair (string-split arg #\=))
|
||||
(var (string->symbol (car pair)))
|
||||
(val (cadr pair)))
|
||||
(when (char=? (string-ref val 0) #\,)
|
||||
(set! val (string-split (substring val 1) #\,)))
|
||||
(cons var val)))
|
||||
args))
|
||||
|
||||
(define (add args)
|
||||
"Add item to the list."
|
||||
(set! todo-list
|
||||
|
@ -141,18 +152,9 @@
|
|||
(append
|
||||
`((id . ,(next-id))
|
||||
(content . ,(string-trim-right (read-delimited ""))))
|
||||
(map (lambda (arg)
|
||||
(let* ((pair (string-split arg #\=))
|
||||
(var (string->symbol (car pair)))
|
||||
(val (cadr pair)))
|
||||
(if (char=? (string-ref val 0) #\,)
|
||||
(set! val (string-split
|
||||
(substring val 1) #\,)))
|
||||
(args->alist args))))))
|
||||
|
||||
(cons var val)))
|
||||
args))))))
|
||||
|
||||
(define (delete args)
|
||||
(define (delete-item args)
|
||||
"Delete the specified element."
|
||||
(set! todo-list
|
||||
(filter (lambda (elm)
|
||||
|
@ -180,6 +182,20 @@
|
|||
(set-current-module (resolve-module '(undone main)))
|
||||
(load rc-file))))
|
||||
|
||||
(define (update args)
|
||||
(let ((item
|
||||
(find (lambda (elm)
|
||||
(let ((id (assq 'id elm)))
|
||||
(and id (eq? (cdr id) (string->number (car args))))))
|
||||
todo-list))
|
||||
(alist (args->alist (cdr args))))
|
||||
(set! todo-list (delete item todo-list))
|
||||
(for-each
|
||||
(lambda (elm)
|
||||
(set! item (assq-set! item (car elm) (cdr elm))))
|
||||
alist)
|
||||
(set! todo-list (append (list item) todo-list))))
|
||||
|
||||
(define (main args)
|
||||
(when (and rc-file (file-exists? rc-file))
|
||||
(load-rc-file))
|
||||
|
@ -190,10 +206,13 @@
|
|||
(add (list-tail args 2))
|
||||
(save))
|
||||
((delete)
|
||||
(delete (list-tail args 2))
|
||||
(delete-item (list-tail args 2))
|
||||
(save))
|
||||
((view)
|
||||
(view (list-tail args 2)))
|
||||
((update)
|
||||
(update (list-tail args 2))
|
||||
(save))
|
||||
((views)
|
||||
(display "Defined views:")
|
||||
(newline)
|
||||
|
|
Loading…
Reference in a new issue