mirror of
https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
synced 2023-12-21 10:23:00 +01:00
Add io.with_feedback() context manager for tasks report OK/FAILED
This commit is contained in:
parent
f1ceda3733
commit
4f3402409a
@ -29,10 +29,8 @@ def synchronize():
|
||||
|
||||
~/.todoist-sync
|
||||
"""
|
||||
|
||||
io.important('Syncing tasks with todoist... ', nl=False)
|
||||
todoist.sync()
|
||||
io.success('OK')
|
||||
with io.with_feedback('Syncing tasks with todoist'):
|
||||
todoist.sync()
|
||||
|
||||
|
||||
@cli.command()
|
||||
@ -100,9 +98,8 @@ def add_task(tid, name, project, tags, priority, entry, due, recur):
|
||||
|
||||
Returns the taskwarrior task.
|
||||
"""
|
||||
io.info(f"Importing '{name}' ({project}) - ", nl=False)
|
||||
try:
|
||||
tw_task = taskwarrior.task_add(
|
||||
with io.with_feedback(f"Importing '{name}' ({project})"):
|
||||
return taskwarrior.task_add(
|
||||
name,
|
||||
project=project,
|
||||
tags=tags,
|
||||
@ -112,11 +109,6 @@ def add_task(tid, name, project, tags, priority, entry, due, recur):
|
||||
recur=recur,
|
||||
todoist_id=tid,
|
||||
)
|
||||
except:
|
||||
io.error('FAILED')
|
||||
else:
|
||||
io.success('OK')
|
||||
return tw_task
|
||||
|
||||
|
||||
def task_prompt(**task_data):
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Utilities for pretty output """
|
||||
|
||||
import contextlib
|
||||
from click import echo, prompt as cprompt, style
|
||||
|
||||
|
||||
@ -47,3 +48,16 @@ def task(task):
|
||||
output += f'{key}: {value}\n'
|
||||
|
||||
echo(output)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def with_feedback(description, success_status='OK', error_status='FAILED'):
|
||||
info(f'{description}... ', nl=False)
|
||||
try:
|
||||
yield
|
||||
except Exception as e:
|
||||
error(f'{error_status} ({e})')
|
||||
raise
|
||||
else:
|
||||
success(success_status)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user