From e22c8650ae1cea9455c9bc419a90cdda8a4dc607 Mon Sep 17 00:00:00 2001 From: Matt Snider Date: Sat, 13 Jul 2019 12:29:55 +0200 Subject: [PATCH] When a parse error occurs for recur, allow user to manually input --- TODO.md | 1 - todoist_taskwarrior/cli.py | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 4f9c2a2..f38b151 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,5 @@ * `revert` command that deletes all tasks with `todoist_id` * Save skipped list so we don't prompt user on next run -* On exception, give user opportunity to manually enter value * Allow input of scheduled, wait diff --git a/todoist_taskwarrior/cli.py b/todoist_taskwarrior/cli.py index a4b96c0..862b5c4 100644 --- a/todoist_taskwarrior/cli.py +++ b/todoist_taskwarrior/cli.py @@ -141,7 +141,7 @@ def migrate(ctx, interactive, sync, map_project, map_tag): # Dates data['entry'] = utils.parse_date(task['date_added']) data['due'] = utils.parse_date(task['due_date_utc']) - data['recur'] = utils.parse_recur(task['date_string']) + data['recur'] = parse_recur_or_prompt(task['date_string']) io.important(f'Task {idx + 1} of {len(tasks)}: {name}') @@ -230,7 +230,7 @@ def add_task_interactive(**task_data): **task_data, 'recur': io.prompt( 'Set recurrence (todoist style)', - default=task_data['recur'], + default='', value_proc=validation.validate_recur, ), }, @@ -267,6 +267,18 @@ def add_task_interactive(**task_data): return add_task(**task_data) +def parse_recur_or_prompt(value): + try: + return utils.parse_recur(value) + except errors.UnsupportedRecurrence: + io.error('Unsupported recurrence: %s. Please enter a valid value' % value) + return io.prompt( + 'Set recurrence (todoist style)', + default='', + value_proc=validation.validate_recur, + ) + + """ Entrypoint """ if __name__ == '__main__':