import click


def to_cli_command(func, callback):
    """
    Convert a stdio command function into a Click command and return it
    """
    if "cli_command" not in vars(func):
        raise ValueError("Function is not a CLI method")

    # Add params
    cli_params = []
    for cli_param in func.cli_params:
        cli_params.append(cli_param.to_cli_parameter())

    cli_name = func.__name__.replace("_", "-")
    command = click.Command(
        name=cli_name,
        help=func.help_text,
        short_help=func.short_help_text,
        params=cli_params,
        callback=callback)

    return command