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 format)
|
||||||
#:use-module (ice-9 rdelim)
|
#:use-module (ice-9 rdelim)
|
||||||
#:use-module (oop goops)
|
#:use-module (oop goops)
|
||||||
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (undone view)
|
#:use-module (undone view)
|
||||||
#:export (main))
|
#:export (main))
|
||||||
|
|
||||||
|
@ -133,6 +134,16 @@
|
||||||
todo-list)))
|
todo-list)))
|
||||||
1))
|
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)
|
(define (add args)
|
||||||
"Add item to the list."
|
"Add item to the list."
|
||||||
(set! todo-list
|
(set! todo-list
|
||||||
|
@ -141,18 +152,9 @@
|
||||||
(append
|
(append
|
||||||
`((id . ,(next-id))
|
`((id . ,(next-id))
|
||||||
(content . ,(string-trim-right (read-delimited ""))))
|
(content . ,(string-trim-right (read-delimited ""))))
|
||||||
(map (lambda (arg)
|
(args->alist args))))))
|
||||||
(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) #\,)))
|
|
||||||
|
|
||||||
(cons var val)))
|
(define (delete-item args)
|
||||||
args))))))
|
|
||||||
|
|
||||||
(define (delete args)
|
|
||||||
"Delete the specified element."
|
"Delete the specified element."
|
||||||
(set! todo-list
|
(set! todo-list
|
||||||
(filter (lambda (elm)
|
(filter (lambda (elm)
|
||||||
|
@ -180,6 +182,20 @@
|
||||||
(set-current-module (resolve-module '(undone main)))
|
(set-current-module (resolve-module '(undone main)))
|
||||||
(load rc-file))))
|
(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)
|
(define (main args)
|
||||||
(when (and rc-file (file-exists? rc-file))
|
(when (and rc-file (file-exists? rc-file))
|
||||||
(load-rc-file))
|
(load-rc-file))
|
||||||
|
@ -190,10 +206,13 @@
|
||||||
(add (list-tail args 2))
|
(add (list-tail args 2))
|
||||||
(save))
|
(save))
|
||||||
((delete)
|
((delete)
|
||||||
(delete (list-tail args 2))
|
(delete-item (list-tail args 2))
|
||||||
(save))
|
(save))
|
||||||
((view)
|
((view)
|
||||||
(view (list-tail args 2)))
|
(view (list-tail args 2)))
|
||||||
|
((update)
|
||||||
|
(update (list-tail args 2))
|
||||||
|
(save))
|
||||||
((views)
|
((views)
|
||||||
(display "Defined views:")
|
(display "Defined views:")
|
||||||
(newline)
|
(newline)
|
||||||
|
|
Loading…
Reference in a new issue