From b624aa77e61ffdd8831354b8c1f57b0b383e5dc5 Mon Sep 17 00:00:00 2001 From: Matt Snider Date: Mon, 25 Mar 2019 22:08:24 +0100 Subject: [PATCH] Add `clean` command to remove todoist cache --- todoist_taskwarrior/cli.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/todoist_taskwarrior/cli.py b/todoist_taskwarrior/cli.py index 0e8cc44..b075463 100644 --- a/todoist_taskwarrior/cli.py +++ b/todoist_taskwarrior/cli.py @@ -6,9 +6,16 @@ from taskw import TaskWarrior from todoist.api import TodoistAPI from . import utils, io + +# This is the location where the todoist +# data will be cached. +TODOIST_CACHE = '~/.todoist-sync/' + + todoist = None taskwarrior = None + """ CLI Commands """ @click.group() @@ -33,6 +40,27 @@ def synchronize(): todoist.sync() +@cli.command() +@click.confirmation_option(prompt=f'Are you sure you want to delete {TODOIST_CACHE}?') +def clean(): + """Remove the data stored in the Todoist task cache. + + NOTE - the local Todoist data cache is usually located at: + + ~/.todoist-sync + """ + cache_dir = os.path.expanduser(TODOIST_CACHE) + + # Delete all files in directory + for file_entry in os.scandir(cache_dir): + with io.with_feedback(f'Removing file {file_entry.path}'): + os.remove(file_entry) + + # Delete directory + with io.with_feedback(f'Removing directory {cache_dir}'): + os.rmdir(cache_dir) + + @cli.command() @click.option('-i', '--interactive', is_flag=True, default=False, help='Interactively choose which tasks to import and modify them ' @@ -198,7 +226,7 @@ if __name__ == '__main__': io.error('TODOIST_API_KEY environment variable not specified. Exiting.') exit(1) - todoist = TodoistAPI(todoist_api_key) + todoist = TodoistAPI(todoist_api_key, cache=TODOIST_CACHE) # Create the TaskWarrior client, overriding config to # create a `todoist_id` field which we'll use to