mirror of
				https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
				synced 2025-10-31 10:02:42 +01:00 
			
		
		
		
	Add --map-tag SRC=DST option to translate or remove tags
This commit is contained in:
		| @@ -17,17 +17,17 @@ def validate(fn, value): | |||||||
|     return fn(None, None, value) |     return fn(None, None, value) | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_validate_map_project(): | def test_validate_map(): | ||||||
|     # Simple |     # Simple | ||||||
|     assert validate(utils.validate_map_project, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'} |     assert validate(utils.validate_map, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'} | ||||||
|  |  | ||||||
|     # Missing DST |     # Missing DST | ||||||
|     assert validate(utils.validate_map_project, ('HELLO=',)) == {'HELLO': None} |     assert validate(utils.validate_map, ('HELLO=',)) == {'HELLO': None} | ||||||
|  |  | ||||||
|     # Multiple |     # 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 '=' |     # Invalid, no '=' | ||||||
|     with pytest.raises(click.BadParameter): |     with pytest.raises(click.BadParameter): | ||||||
|         assert validate(utils.validate_map_project, ('FOO',)) == None |         assert validate(utils.validate_map, ('FOO',)) == None | ||||||
|  |  | ||||||
|   | |||||||
| @@ -68,11 +68,15 @@ def clean(): | |||||||
| @click.option('--sync/--no-sync', default=True, | @click.option('--sync/--no-sync', default=True, | ||||||
|         help='Enable/disable Todoist synchronization of the local task cache.') |         help='Enable/disable Todoist synchronization of the local task cache.') | ||||||
| @click.option('-p', '--map-project', metavar='SRC=DST', multiple=True, | @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. ' |         help='Project names specified will be translated from SRC to DST. ' | ||||||
|              'If DST is omitted, the project will be unset when SRC matches.') |              '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 | @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. |     """Migrate tasks from Todoist to Taskwarrior. | ||||||
|  |  | ||||||
|     By default this command will synchronize with the Todoist servers |     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['priority'] = utils.parse_priority(task['priority']) | ||||||
|         data['tags'] = [ |         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'] |             for l_id in task['labels'] | ||||||
|         ] |         ] | ||||||
|         data['entry'] = utils.parse_date(task['date_added']) |         data['entry'] = utils.parse_date(task['date_added']) | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ from datetime import datetime | |||||||
|  |  | ||||||
| """ Validation """ | """ Validation """ | ||||||
|  |  | ||||||
| def validate_map_project(ctx, param, value): | def validate_map(ctx, param, value): | ||||||
|     map_project = {} |     map_project = {} | ||||||
|     for mapping in value: |     for mapping in value: | ||||||
|         try: |         try: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matt Snider
					Matt Snider