#!/usr/bin/python -tt
# -*- coding: utf-8 -*-


import sys
import os

import kobo.exceptions
import kobo.cli

# assuming all commands are in {{ project_name }}/commands/cmd_*.py modules
import {{ project_name }}.commands


# inherit container to make sure nobody will change plugins I registered
class {{ project_name|camel }}CommandContainer(kobo.cli.CommandContainer):
    # uncomment and update following text
    # to make it available in help-rst output
    # (which can be converted to a man page)
    #
    #_description = "brief description/purpose of the program"
    #_copyright = "(c) Foo Bar, Inc."
    #_contact = "foo.bar@example.com"
    #_authors = [
    #    "Spam Eggs <spam.eggs@example.com>",
    #]
    pass


def main(args=None):
    # register project specific commands
    {{ project_name|camel }}CommandContainer.register_module({{ project_name }}.commands, prefix="cmd_")

    # initialize command container
    command_container = {{ project_name|camel }}CommandContainer()
    parser = kobo.cli.CommandOptionParser(
        command_container=command_container, # plugin container with registered commands
        add_username_password_options=True,  # include auth options to each command
    )

    try:
        parser.run(args)
    except kobo.exceptions.ImproperlyConfigured, ex:
        sys.stderr.write("\n\nError: Improperly configured: %s\n" % ex)
        return 3
    return 0


if __name__ == "__main__":
    sys.exit(main())
