From c1d5edef5c8dbc94c5d55d11bcb863a6af29b237 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Mon, 13 Nov 2023 09:04:05 -0500 Subject: [PATCH] feat: add limit option to ls (#314) --- toggl/cli/commands.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/toggl/cli/commands.py b/toggl/cli/commands.py index 0356cc5..60dd609 100644 --- a/toggl/cli/commands.py +++ b/toggl/cli/commands.py @@ -213,8 +213,9 @@ def get_entries(ctx, use_reports, **conditions): help='Defines a set of fields of time entries, which will be displayed. It is also possible to modify ' 'default set of fields using \'+\' and/or \'-\' characters. Supported values: ' + types.FieldsType.format_fields_for_help(api.TimeEntry)) +@click.option('--limit', '-n', type=int, help='The number of entries to display') @click.pass_context -def entry_ls(ctx, fields, today, use_reports, **conditions): +def entry_ls(ctx, fields, today, use_reports, limit, **conditions): """ Lists time entries the user has access to. @@ -239,6 +240,9 @@ def entry_ls(ctx, fields, today, use_reports, **conditions): entities = get_entries(ctx, use_reports, **conditions) + if limit: + entities = entities[:limit] + if ctx.obj.get('simple'): if ctx.obj.get('header'): click.echo('\t'.join([click.style(field.capitalize(), **theme.header) for field in fields]))