toggl-cli icon indicating copy to clipboard operation
toggl-cli copied to clipboard

Removing multiple entities with single command

Open AuHau opened this issue 5 years ago • 3 comments

Currently, all rm subcommands accept only one ID/Name, it would be more user-friendly if they would accept "infinite" number of arguments.

AuHau avatar Jan 21 '19 19:01 AuHau

I think this can be done by making the argument spec as variadic argument (accepting infinte arguments and setting it as required such that at least one arg is required.). Then iterating through all values, removing them one by one.

[...]
@click.argument('spec', nargs=-1, required=True)
[...]
    for sp in spec:
         helpers.entity_remove(api.TimeEntry, sp, ('id', 'description'), obj=ctx.obj)
[...]

While this implementation prevents breaking previous versions, it has an issue. If one of the amidst time entry doesn't exist, the program halts. Is there any way to prevent this issue?

dkvc avatar Feb 18 '23 15:02 dkvc

How exactly does it halt? Does it just throw an exception? Can't you wrap that in a try/except block?

StanczakDominik avatar Feb 23 '23 19:02 StanczakDominik

In entity remove, this line halts the program if entry is not found.

[...]
def entity_remove():
[...]
    if not entities:
        click.echo('{} not found!'.format(cls.get_name(verbose=True)), color=theme.error_color)
        exit(44)
[...]

While exit(44) can be removed, the terminal returns exit status 0 even if not found.

dkvc avatar Feb 24 '23 04:02 dkvc