diff --git a/swh/indexer/cli.py b/swh/indexer/cli.py --- a/swh/indexer/cli.py +++ b/swh/indexer/cli.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information import functools +import json import time import click @@ -89,6 +90,22 @@ click.echo('\t' + ', '.join(sorted(supported_mappings))) +@mapping.command('translate') +@click.argument('mapping-name') +@click.argument('file', type=click.File('rb')) +def mapping_translate(mapping_name, file): + """Prints the list of known mappings.""" + mapping_cls = [cls for cls in metadata_dictionary.MAPPINGS.values() + if cls.name == mapping_name] + if not mapping_cls: + raise click.ClickException('Unknown mapping {}'.format(mapping_name)) + assert len(mapping_cls) == 1 + mapping_cls = mapping_cls[0] + mapping = mapping_cls() + codemeta_doc = mapping.translate(file.read()) + click.echo(json.dumps(codemeta_doc, indent=4)) + + @cli.group('schedule') @click.option('--scheduler-url', '-s', default=None, help="URL of the scheduler API")