# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/cli/netcdfy.ipynb.

# %% auto 0
__all__ = ['import_handler', 'main']

# %% ../../nbs/cli/netcdfy.ipynb 2
from fastcore.script import *
import importlib

from ..configs import nc_tpl_path

# %% ../../nbs/cli/netcdfy.ipynb 3
def import_handler(handler_name, fn_name='encode'):
    try:
        handler = importlib.import_module(handler_name)
        return getattr(handler, fn_name)

    except (ImportError, AttributeError):
        print(f"Failed to import function: {fn_name}")

# %% ../../nbs/cli/netcdfy.ipynb 4
@call_parse
def main(handler_name: str,  # Handler's name (e.g helcom, ...)
         src: str,           # Path to dataset to encode
         dest: str,          # Path to converted NetCDF4
         ):
    "Encode MARIS dataset as NetCDF"
    print(f'Encoding: {handler_name} ...')
    encode = import_handler(f'marisco.handlers.{handler_name}')
    encode(src, dest, get_nc_tpl_path())
