Add the 'done' command

This commit is contained in:
Danny Robson 2020-05-21 10:34:59 +10:00
parent 16224076ec
commit 9a18e8a940

View File

@ -16,6 +16,14 @@ def add(session: sa.orm.Session, title: str):
show_by_obj(obj) 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): def rm(session: sa.orm.Session, index: int):
session.query(Task).filter(Task.id == index).delete() session.query(Task).filter(Task.id == index).delete()
@ -53,6 +61,7 @@ if __name__ == '__main__':
actions = { actions = {
'add': add, 'add': add,
'done': done,
'rm': rm, 'rm': rm,
'show': show_by_id, 'show': show_by_id,
'ls': ls 'ls': ls
@ -66,6 +75,10 @@ if __name__ == '__main__':
add_parser.set_defaults(func=add) add_parser.set_defaults(func=add)
add_parser.add_argument("title", type=str) 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 = subparsers.add_parser('rm')
rm_parser.set_defaults(func=rm) rm_parser.set_defaults(func=rm)
rm_parser.add_argument("index", type=int) rm_parser.add_argument("index", type=int)