# 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)
# 
# def start_box(box, provision_with=None):
#     # if the vm is suspended, just resume it
#     res = 0
# 
#     provision = provision_with or []
# 
#     if 'shell' not in provision and box.status() != 'not created':
#         provision.append('shell')
# 
#     extra_args = []
#     if provision:
#         extra_args = ['--provision-with', ','.join(provision)]
# 
#     manual_provision = False
#     if box.status() == 'saved':
#         manual_provision = True
#         click.echo('Resuming box %s' % box.name())
# 
#     if not box.is_running():
#         try:
#             extra_args_copy = extra_args[:]
#             if '--provision-with' in extra_args_copy:
#                 extra_args_copy.insert(0, '--provision')
#             res = box.up(*extra_args_copy)
#         except (ExposeTimeout, ExposeConnectionError):
#             warning('warning: expose is not available at the moment')
#     else:
#         hist = box.history()
#         if not hist or (
#             'failed_at' in hist[-1] and
#                 hist[-1]['failed_at']
#         ) or hist[-1]['stats'][box.name()]['unreachable'] > 0:
#             # run provisioning if last one failed
#             res = box.vagrant('provision')
# 
#         box.expose()  # just in case
# 
#     if manual_provision:
#         box.vagrant('provision', *extra_args)
# 
#     if res == 0 or res is True:
#         timestamp(render_cli('provision-success', box=box))
#     else:
#         timestamp(render_cli('provision-failure'))
# 
#     # refresh cache
#     list_vms(clear_cache_only=True)
# 
#     return res
# 
# def fatal(text, code=1, **kwargs):
#     error(text, **kwargs)
#     sys.exit(code)


import click
from requests.exceptions import HTTPError
from aeriscloud.cli.helpers import standard_options, Command, start_box, fatal
#!/usr/bin/env python





def _parse_provision(ctx, param, value):
    if not value:
        return []
    provisioners = value.split(',')
    for provisioner in provisioners:
        if provisioner not in ['ansible', 'shell']:
            raise click.BadParameter('provisioner must be on of ansible or '
                                     'shell')
    return provisioners


@click.command(cls=Command)
@click.option('--provision-with', default=None, callback=_parse_provision)
@standard_options(start_prompt=False)
def cli(box, provision_with):
    """
    Starts the given box and provision it
    """
    try:

# 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)
# 
# def start_box(box, provision_with=None):
#     # if the vm is suspended, just resume it
#     res = 0
# 
#     provision = provision_with or []
# 
#     if 'shell' not in provision and box.status() != 'not created':
#         provision.append('shell')
# 
#     extra_args = []
#     if provision:
#         extra_args = ['--provision-with', ','.join(provision)]
# 
#     manual_provision = False
#     if box.status() == 'saved':
#         manual_provision = True
#         click.echo('Resuming box %s' % box.name())
# 
#     if not box.is_running():
#         try:
#             extra_args_copy = extra_args[:]
#             if '--provision-with' in extra_args_copy:
#                 extra_args_copy.insert(0, '--provision')
#             res = box.up(*extra_args_copy)
#         except (ExposeTimeout, ExposeConnectionError):
#             warning('warning: expose is not available at the moment')
#     else:
#         hist = box.history()
#         if not hist or (
#             'failed_at' in hist[-1] and
#                 hist[-1]['failed_at']
#         ) or hist[-1]['stats'][box.name()]['unreachable'] > 0:
#             # run provisioning if last one failed
#             res = box.vagrant('provision')
# 
#         box.expose()  # just in case
# 
#     if manual_provision:
#         box.vagrant('provision', *extra_args)
# 
#     if res == 0 or res is True:
#         timestamp(render_cli('provision-success', box=box))
#     else:
#         timestamp(render_cli('provision-failure'))
# 
#     # refresh cache
#     list_vms(clear_cache_only=True)
# 
#     return res
# 
# def fatal(text, code=1, **kwargs):
#     error(text, **kwargs)
#     sys.exit(code)


# Path: aeriscloud/cli/aeris/up.py
import click
from requests.exceptions import HTTPError
from aeriscloud.cli.helpers import standard_options, Command, start_box, fatal

#!/usr/bin/env python





def _parse_provision(ctx, param, value):
    if not value:
        return []
    provisioners = value.split(',')
    for provisioner in provisioners:
        if provisioner not in ['ansible', 'shell']:
            raise click.BadParameter('provisioner must be on of ansible or '
                                     'shell')
    return provisioners


@click.command(cls=Command)
@click.option('--provision-with', default=None, callback=_parse_provision)
@standard_options(start_prompt=False)
def cli(box, provision_with):
    """
    Starts the given box and provision it
    """
    try:

        return start_box(box, provision_with)