diff --git a/fre/catalog/frecatalog.py b/fre/catalog/frecatalog.py index 9f43fbb4..58149e5e 100644 --- a/fre/catalog/frecatalog.py +++ b/fre/catalog/frecatalog.py @@ -6,6 +6,7 @@ #import catalogbuilder from catalogbuilder.scripts import gen_intake_gfdl from catalogbuilder.scripts import test_catalog +from catalogbuilder.scripts import combine_cats @click.group(help=click.style(" - access fre catalog subcommands", fg=(64,94,213))) @@ -47,5 +48,15 @@ def validate(context, json_path, json_template_path, test_failure): """ - Validate a catalog against catalog schema """ context.forward(test_catalog.main) +@catalog_cli.command() +@click.option('--input', required = True, multiple = True, + help = 'Catalog json files to be merged, space-separated') +@click.option('--output', required = True, nargs = 1, + help = 'Merged catalog') +@click.pass_context +def merge(context, input, output): + """ - Merge two or more more catalogs into one """ + context.invoke(combine_cats.combine_cats, inputfiles=input, output_path=output) + if __name__ == "__main__": catalog_cli() diff --git a/fre/tests/test_fre_catalog_cli.py b/fre/tests/test_fre_catalog_cli.py index ce9c764a..79a1d35a 100644 --- a/fre/tests/test_fre_catalog_cli.py +++ b/fre/tests/test_fre_catalog_cli.py @@ -36,3 +36,15 @@ def test_cli_fre_catalog_builder_help(): ''' fre catalog builder --help ''' result = runner.invoke(fre.fre, args=["catalog", "builder", "--help"]) assert result.exit_code == 0 + +def test_cli_fre_catalog_merge(): + result = runner.invoke(fre.fre, args=["catalog", "merge"]) + expected_stdout = "Error: Missing option '--input'." + assert all( [ + result.exit_code == 2, + expected_stdout in result.stdout.split('\n') + ] ) + +def test_cli_fre_catalog_merge_help(): + result = runner.invoke(fre.fre, args=["catalog", "merge", "--help"]) + assert result.exit_code == 0