diff --git a/swh/storage/cli.py b/swh/storage/cli.py --- a/swh/storage/cli.py +++ b/swh/storage/cli.py @@ -159,8 +159,35 @@ type=int, help="Stop after processing this many objects. Default is to " "run forever.", ) +@click.option( + "--type", + "-t", + "object_types", + default=[], + type=click.Choice( + # use a hardcoded list to prevent having to load the + # replay module at cli loading time + [ + "origin", + "origin_visit", + "origin_visit_status", + "snapshot", + "revision", + "release", + "directory", + "content", + "skipped_content", + "metadata_authority", + "metadata_fetcher", + "raw_extrinsic_metadata", + "extid", + ] + ), + help="Object types to replay", + multiple=True, +) @click.pass_context -def replay(ctx, stop_after_objects): +def replay(ctx, stop_after_objects, object_types): """Fill a Storage by reading a Journal. There can be several 'replayers' filling a Storage as long as they use @@ -178,6 +205,8 @@ storage = get_storage(**conf.pop("storage")) client_cfg = conf.pop("journal_client") + if object_types: + client_cfg["object_types"] = object_types if stop_after_objects: client_cfg["stop_after_objects"] = stop_after_objects try: diff --git a/swh/storage/tests/test_cli.py b/swh/storage/tests/test_cli.py --- a/swh/storage/tests/test_cli.py +++ b/swh/storage/tests/test_cli.py @@ -18,6 +18,7 @@ from swh.model.model import Snapshot, SnapshotBranch, TargetType from swh.storage import get_storage from swh.storage.cli import storage as cli +from swh.storage.replay import object_converter_fn logger = logging.getLogger(__name__) @@ -109,3 +110,16 @@ **snapshot_dict, "next_branch": None, } + + +def test_replay_type_list(): + result = invoke("replay", "--help",) + assert result.exit_code == 0, result.output + types_in_help = re.findall("--type [[]([a-z_|]+)[]]", result.output) + assert len(types_in_help) == 1 + types = types_in_help[0].split("|") + + assert sorted(types) == sorted(list(object_converter_fn.keys())), ( + "Make sure the list of accepted types in cli.py " + "matches implementation in replay.py" + )