diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index e50e904a..0925212e 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -6391,10 +6391,22 @@ def handle_list_tasks(goptions, session, args): parser.add_option("--host", help=_("Only tasks for this host")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not display the column headers")) + parser.add_option("--before", + help=_("List builds built before this time, " + "time is specified as timestamp or date/time in any " + "format which can be parsed by dateutil.parser. e.g. " + "\"2020-12-31 12:35\" or \"December 31st 12:35\"")) + parser.add_option("--after", + help=_("List builds built after this time (same format as for --before")) + parser.add_option("--all", action="store_true", + help=_("List also finished tasks (valid only with --after)")) (options, args) = parser.parse_args(args) if len(args) != 0: parser.error(_("This command takes no arguments")) + if options.all and not options.after: + parser.error(_("--all must be used with --after")) + activate_session(session, goptions) tasklist = _list_tasks(options, session) if not tasklist: diff --git a/cli/koji_cli/lib.py b/cli/koji_cli/lib.py index 0e2a7240..472bbe99 100644 --- a/cli/koji_cli/lib.py +++ b/cli/koji_cli/lib.py @@ -722,9 +722,14 @@ def _list_tasks(options, session): "Retrieve a list of tasks" callopts = { - 'state': [koji.TASK_STATES[s] for s in ('FREE', 'OPEN', 'ASSIGNED')], 'decode': True, } + if not options.all: + callopts['state'] = [koji.TASK_STATES[s] for s in ('FREE', 'OPEN', 'ASSIGNED')] + if options.after: + callopts['startedAfter'] = options.after + if options.before: + callopts['startedBefore'] = options.before if getattr(options, 'mine', False): if getattr(options, 'user', None): diff --git a/tests/test_cli/test_list_tasks.py b/tests/test_cli/test_list_tasks.py index ac45f298..a701219b 100644 --- a/tests/test_cli/test_list_tasks.py +++ b/tests/test_cli/test_list_tasks.py @@ -22,6 +22,9 @@ class TestListTasks(unittest.TestCase): options.method = None options.channel = None options.host = None + options.before = None + options.after = None + options.all = False session = mock.MagicMock(name='session') session.getLoggedInUser.return_value = {'id': 1, 'username': 'name'} session.listTasks.return_value = [] @@ -259,4 +262,11 @@ Options: --channel=CHANNEL Only tasks in this channel --host=HOST Only tasks for this host --quiet Do not display the column headers + --before=BEFORE List builds built before this time, time is specified as + timestamp or date/time in any format which can be parsed + by dateutil.parser. e.g. "2020-12-31 12:35" or "December + 31st 12:35" + --after=AFTER List builds built after this time (same format as for + --before + --all List also finished tasks (valid only with --after) """ % self.progname)