Skip to content

Commit

Permalink
Merge pull request #211 from NOAA-GFDL/catalog-merge
Browse files Browse the repository at this point in the history
Add click bindings for 'fre catalog merge'
  • Loading branch information
ilaflott authored Oct 20, 2024
2 parents a3c95cd + 9ff8eee commit f7de530
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fre/catalog/frecatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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()
12 changes: 12 additions & 0 deletions fre/tests/test_fre_catalog_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f7de530

Please sign in to comment.