mirror of
				https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
				synced 2025-10-31 10:02:42 +01:00 
			
		
		
		
	Add io.with_feedback() context manager for tasks report OK/FAILED
This commit is contained in:
		| @@ -29,10 +29,8 @@ def synchronize(): | |||||||
|  |  | ||||||
|         ~/.todoist-sync |         ~/.todoist-sync | ||||||
|     """ |     """ | ||||||
|  |     with io.with_feedback('Syncing tasks with todoist'): | ||||||
|     io.important('Syncing tasks with todoist... ', nl=False) |  | ||||||
|         todoist.sync() |         todoist.sync() | ||||||
|     io.success('OK') |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @cli.command() | @cli.command() | ||||||
| @@ -100,9 +98,8 @@ def add_task(tid, name, project, tags, priority, entry, due, recur): | |||||||
|  |  | ||||||
|     Returns the taskwarrior task. |     Returns the taskwarrior task. | ||||||
|     """ |     """ | ||||||
|     io.info(f"Importing '{name}' ({project}) - ", nl=False) |     with io.with_feedback(f"Importing '{name}' ({project})"): | ||||||
|     try: |         return taskwarrior.task_add( | ||||||
|         tw_task = taskwarrior.task_add( |  | ||||||
|             name, |             name, | ||||||
|             project=project, |             project=project, | ||||||
|             tags=tags, |             tags=tags, | ||||||
| @@ -112,11 +109,6 @@ def add_task(tid, name, project, tags, priority, entry, due, recur): | |||||||
|             recur=recur, |             recur=recur, | ||||||
|             todoist_id=tid, |             todoist_id=tid, | ||||||
|         ) |         ) | ||||||
|     except: |  | ||||||
|         io.error('FAILED') |  | ||||||
|     else: |  | ||||||
|         io.success('OK') |  | ||||||
|         return tw_task |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def task_prompt(**task_data): | def task_prompt(**task_data): | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| """Utilities for pretty output """ | """Utilities for pretty output """ | ||||||
|  |  | ||||||
|  | import contextlib | ||||||
| from click import echo, prompt as cprompt, style | from click import echo, prompt as cprompt, style | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -47,3 +48,16 @@ def task(task): | |||||||
|         output += f'{key}: {value}\n' |         output += f'{key}: {value}\n' | ||||||
|  |  | ||||||
|     echo(output) |     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) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matt Snider
					Matt Snider