AuHau / toggl-cli

A simple command-line interface for toggl.com

Home Page:https://toggl.uhlir.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing multiple entities with single command

AuHau opened this issue · comments

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

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?

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

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.