# Path: aeriscloud/ansible.py
# def ansible_env(env):
#     def __init__(self, inventory, hostname):
#     def ssh_host(self):
#     def ssh_key(self):
#     def ssh_user(self):
#     def variables(self):
# def get_organization_list():
# def get_env_path(organization):
# def get_env_file(organization, environment):
# def list_jobs():
# def get_job_file(job):
# def get_inventory_file(inventory):
# def get_inventory_list():
# def run_job(job, inventory, *args, **kwargs):
# def run_env(organization, environment, inventory, *args, **kwargs):
# def run_playbook(playbook, inventory, *args, **kwargs):
# def run(inventory, shell_cmd, limit, *args, **kwargs):
# def shell(inventory, *args, **kwargs):
#     def __init__(self, inventory_path):
#     def get_ansible_inventory(self):
#     def get_hosts(self, pattern='all'):
#     def get_groups(self):
# class ACHost(object):
# class Inventory(object):
# 
# Path: aeriscloud/cli/helpers.py
# def standard_options(multiple=False, start_prompt=True):
#     """
#     Add the standard --project and --box options to a command
#     :param multiple: Whether to find a single or multiple boxes
#     :param start_prompt: When using single boxes, ask the user to start it if
#                          offline
#     """
#     if multiple:
#         return _multi_box_decorator
#     else:
#         return _single_box_decorator(start_prompt)
# 
# class Command(click.Command):
#     # This is inherited by the Context to switch between pure POSIX and
#     # argparse-like argument parsing. Setting it to false will push any
#     # unknown flag to the argument located where the flag was declared
#     allow_interspersed_args = config.get('config', 'posix', default=False)
# 
#     def __init__(self, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         super(Command, self).__init__(context_settings=cs,
#                                       *args, **kwargs)


import click
import os
import sys
from aeriscloud.ansible import ansible_path, get_job_file, list_jobs
from aeriscloud.cli.helpers import standard_options, Command


@click.command(cls=Command)
@click.argument('job', required=False)
@click.argument('extra', nargs=-1)
@standard_options(start_prompt=False)
def cli(box, job, extra):
    """
    Run a maintenance job in a box.

    Call without a job to get the job list
    """
    if not job:
        for job in list_jobs():
            (job_name, job_desc) = job
            if not job_desc:
                print('* %s' % (
                    click.style(job_name, bold=True),
                ))
            else:
                print('* %-35s - %s' % (
                    click.style(job_name, bold=True),
                    job_desc
                ))
        return

    if not box.is_running():
        click.secho('error: box %s is not running' % box.name(), fg='red')
        sys.exit(1)


# Path: aeriscloud/ansible.py
# def ansible_env(env):
#     def __init__(self, inventory, hostname):
#     def ssh_host(self):
#     def ssh_key(self):
#     def ssh_user(self):
#     def variables(self):
# def get_organization_list():
# def get_env_path(organization):
# def get_env_file(organization, environment):
# def list_jobs():
# def get_job_file(job):
# def get_inventory_file(inventory):
# def get_inventory_list():
# def run_job(job, inventory, *args, **kwargs):
# def run_env(organization, environment, inventory, *args, **kwargs):
# def run_playbook(playbook, inventory, *args, **kwargs):
# def run(inventory, shell_cmd, limit, *args, **kwargs):
# def shell(inventory, *args, **kwargs):
#     def __init__(self, inventory_path):
#     def get_ansible_inventory(self):
#     def get_hosts(self, pattern='all'):
#     def get_groups(self):
# class ACHost(object):
# class Inventory(object):
# 
# Path: aeriscloud/cli/helpers.py
# def standard_options(multiple=False, start_prompt=True):
#     """
#     Add the standard --project and --box options to a command
#     :param multiple: Whether to find a single or multiple boxes
#     :param start_prompt: When using single boxes, ask the user to start it if
#                          offline
#     """
#     if multiple:
#         return _multi_box_decorator
#     else:
#         return _single_box_decorator(start_prompt)
# 
# class Command(click.Command):
#     # This is inherited by the Context to switch between pure POSIX and
#     # argparse-like argument parsing. Setting it to false will push any
#     # unknown flag to the argument located where the flag was declared
#     allow_interspersed_args = config.get('config', 'posix', default=False)
# 
#     def __init__(self, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         super(Command, self).__init__(context_settings=cs,
#                                       *args, **kwargs)


# Path: aeriscloud/cli/aeris/job.py
import click
import os
import sys
from aeriscloud.ansible import ansible_path, get_job_file, list_jobs
from aeriscloud.cli.helpers import standard_options, Command



@click.command(cls=Command)
@click.argument('job', required=False)
@click.argument('extra', nargs=-1)
@standard_options(start_prompt=False)
def cli(box, job, extra):
    """
    Run a maintenance job in a box.

    Call without a job to get the job list
    """
    if not job:
        for job in list_jobs():
            (job_name, job_desc) = job
            if not job_desc:
                print('* %s' % (
                    click.style(job_name, bold=True),
                ))
            else:
                print('* %-35s - %s' % (
                    click.style(job_name, bold=True),
                    job_desc
                ))
        return

    if not box.is_running():
        click.secho('error: box %s is not running' % box.name(), fg='red')
        sys.exit(1)


    playbook = os.path.join(ansible_path, 'dev_jobs.yml')