From 0f55007a6083939e08d58e64c799ed7c8b8caca5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 21 May 2020 10:43:40 +1000 Subject: [PATCH] Filter 'ls' results by 'active' by default --- src/pyelephant.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pyelephant.py b/src/pyelephant.py index 2aca6e3..aec7c49 100755 --- a/src/pyelephant.py +++ b/src/pyelephant.py @@ -42,8 +42,12 @@ def show_by_id(session: sa.orm.Session, index: int): # ----------------------------------------------------------------------------- -def ls(session: sa.orm.Session): - for i in session.query(Task).order_by(Task.created_at): +def ls(session: sa.orm.Session, _all: False): + vals = session.query(Task).order_by(Task.created_at) + if _all is False: + vals = vals.filter(Task.active is True) + + for i in vals: show_by_obj(session, i) @@ -88,7 +92,8 @@ if __name__ == '__main__': show_parser.add_argument('index', type=int) ls_parser = subparsers.add_parser('ls') - ls_parser.set_defaults(func=ls) + ls_parser.set_defaults(func=ls, _all=False) + ls_parser.add_argument('--all', dest='_all', action='store_const', const='true', help="Show inactive tasks") args = parser.parse_args()