#!/usr/bin/env python
import psychic_disco
from psychic_disco import cli
import os
import sys

def config(value="psychic_disco_config.py"):
    """Specify alternate config file"""


@cli.subcommand
def list_entrypoints(module_name):
    """list all entrypoints for a given module"""
    psychic_disco.attempt_import(module_name)
    print psychic_disco.entry_points()


@cli.subcommand
def discover_entrypoints():
    """search repo for possible entrypoints"""
    psychic_disco.discover_entrypoints(".")
    print psychic_disco.entry_points()


@cli.subcommand
def deploy_lambdas():
    """Deploy the defined lambda functions"""
    psychic_disco.discover_entrypoints(".")
    for ep in psychic_disco.entry_points():
        ep.deploy()


@cli.subcommand
def bundle():
    """Bundle application into a Lambda-friendly deployment package"""
    package = psychic_disco.deployment_package.default()
    package.deploy()


if __name__ == "__main__":
    cli.argument('--config', help='config file', default="psychic_disco_config.py")
    args = cli.parse_args()
    if os.path.exists(args.config):
        config_module = psychic_disco.convert_path_to_module(args.config)
        psychic_disco.attempt_import(config_module)
    args.func(args)
