from __future__ import absolute_import
from nilmdb.printf import *
import nilmdb.client

from argparse import ArgumentDefaultsHelpFormatter as def_form

def setup(self, sub):
    cmd = sub.add_parser("create", help="Create a new stream",
                         formatter_class = def_form,
                         description="""
                         Create a new empty stream at the
                         specified path and with the specifed
                         layout type.
                         """)
    cmd.set_defaults(handler = cmd_create)
    group = cmd.add_argument_group("Required arguments")
    group.add_argument("path",
                       help="Path (in database) of new stream, e.g. /foo/bar")
    group.add_argument("layout",
                       help="Layout type for new stream, e.g. float32_8")

def cmd_create(self):
    """Create new stream"""
    try:
        self.client.stream_create(self.args.path, self.args.layout)
    except nilmdb.client.ClientError as e:
        self.die("Error creating stream: %s", str(e))
