#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import syd
import click
from sqlalchemy import exc
from box import Box

# -----------------------------------------------------------------------------
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


@click.command(context_settings=CONTEXT_SETTINGS)
@click.argument('name')
@click.argument('table')
@click.argument('view_format')
@click.option('--db', default='',
              help='DB filename (SYD_DB_FILENAME environment variable is used if no filename)')
def syd_insert_view(db, name, table, view_format):
    """
    Create a SQL view and a description in the table view (used for printing)
    """

    # open the db
    db_filename = syd.get_db_filename(db)
    db = syd.open_db(db_filename)

    # go
    txt = syd.insert_view(db, name, table, view_format)
    print(txt)

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    syd_insert_view()
