Add --map-tag SRC=DST option to translate or remove tags

This commit is contained in:
Matt Snider 2019-06-09 20:30:47 +02:00
parent 9231ec21af
commit 9f93b92a29
3 changed files with 13 additions and 9 deletions

View File

@ -17,17 +17,17 @@ def validate(fn, value):
return fn(None, None, value)
def test_validate_map_project():
def test_validate_map():
# Simple
assert validate(utils.validate_map_project, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'}
assert validate(utils.validate_map, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'}
# Missing DST
assert validate(utils.validate_map_project, ('HELLO=',)) == {'HELLO': None}
assert validate(utils.validate_map, ('HELLO=',)) == {'HELLO': None}
# Multiple
assert validate(utils.validate_map_project, ('FOO=BAR', 'BAR=BAZZ')) == {'FOO': 'BAR', 'BAR': 'BAZZ'}
assert validate(utils.validate_map, ('FOO=BAR', 'BAR=BAZZ')) == {'FOO': 'BAR', 'BAR': 'BAZZ'}
# Invalid, no '='
with pytest.raises(click.BadParameter):
assert validate(utils.validate_map_project, ('FOO',)) == None
assert validate(utils.validate_map, ('FOO',)) == None

View File

@ -68,11 +68,15 @@ def clean():
@click.option('--sync/--no-sync', default=True,
help='Enable/disable Todoist synchronization of the local task cache.')
@click.option('-p', '--map-project', metavar='SRC=DST', multiple=True,
callback=utils.validate_map_project,
callback=utils.validate_map,
help='Project names specified will be translated from SRC to DST. '
'If DST is omitted, the project will be unset when SRC matches.')
@click.option('-t', '--map-tag', metavar='SRC=DST', multiple=True,
callback=utils.validate_map,
help='Tags specified will be translated from SRC to DST. '
'If DST is omitted, the tag will be removed when SRC matches.')
@click.pass_context
def migrate(ctx, interactive, sync, map_project):
def migrate(ctx, interactive, sync, map_project, map_tag):
"""Migrate tasks from Todoist to Taskwarrior.
By default this command will synchronize with the Todoist servers
@ -111,7 +115,7 @@ def migrate(ctx, interactive, sync, map_project):
)
data['priority'] = utils.parse_priority(task['priority'])
data['tags'] = [
todoist.labels.get_by_id(l_id)['name']
utils.try_map(map_tag, todoist.labels.get_by_id(l_id)['name'])
for l_id in task['labels']
]
data['entry'] = utils.parse_date(task['date_added'])

View File

@ -4,7 +4,7 @@ from datetime import datetime
""" Validation """
def validate_map_project(ctx, param, value):
def validate_map(ctx, param, value):
map_project = {}
for mapping in value:
try: