From 9a18e8a94076e0613003d376640ab5327dff1a66 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 21 May 2020 10:34:59 +1000 Subject: [PATCH] Add the 'done' command --- src/pyelephant.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pyelephant.py b/src/pyelephant.py index 1a42510..2aca6e3 100755 --- a/src/pyelephant.py +++ b/src/pyelephant.py @@ -16,6 +16,14 @@ def add(session: sa.orm.Session, title: str): show_by_obj(obj) +# ----------------------------------------------------------------------------- +def done(session: sa.orm.Session, index: int): + obj = session.query(Task).filter(Task.id == index).one() + assert(obj.active is True) + obj.active = False + session.commit() + + # ----------------------------------------------------------------------------- def rm(session: sa.orm.Session, index: int): session.query(Task).filter(Task.id == index).delete() @@ -53,6 +61,7 @@ if __name__ == '__main__': actions = { 'add': add, + 'done': done, 'rm': rm, 'show': show_by_id, 'ls': ls @@ -66,6 +75,10 @@ if __name__ == '__main__': add_parser.set_defaults(func=add) add_parser.add_argument("title", type=str) + done_parser = subparsers.add_parser('done') + done_parser.set_defaults(func=done) + done_parser.add_argument('index', type=int) + rm_parser = subparsers.add_parser('rm') rm_parser.set_defaults(func=rm) rm_parser.add_argument("index", type=int)