# Path: aeriscloud/cli/helpers.py
# class AerisCLI(click.MultiCommand):
#     def __init__(self, command_dir, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         params = [
#             click.Option(
#                 param_decls=['-v', '--verbose'],
#                 count=True,
#                 help='Make commands verbose, use '
#                      'multiple time for higher verbosity'
#             ),
#             click.Option(
#                 param_decls=['--log-file'],
#                 help='When using the verbose flag, redirects '
#                      'output to this file'
#             )
#         ]
#         super(AerisCLI, self).__init__(context_settings=cs, params=params,
#                                        *args, **kwargs)
#         self.command_dir = command_dir
# 
#         no_setup = 'AC_NO_ASSISTANT' in os.environ \
#                    and os.environ['AC_NO_ASSISTANT'] == '1'
#         if not no_setup and sys.stdout.isatty() and not config.complete():
#             click.echo('''
# It seems it is the first time you are launching AerisCloud, or new
# configuration options were added since the last update. We can guide
# you through a series of questions to setup your configuration.
# ''', err=True)
#             if not click.confirm('Run configuration assistant', default=True):
#                 return
#             from .config import assistant
# 
#             assistant()
# 
#     def list_commands(self, ctx):
#         excluded = ['complete', 'test']
# 
#         rv = [filename[:-3].replace('_', '-') for filename in
#               os.listdir(self.command_dir)
#               if filename.endswith('.py') and
#               filename[:-3] not in excluded and
#               not filename.startswith('__')]
#         rv.sort()
#         return rv
# 
#     def get_command(self, ctx, name):
#         ns = {}
#         fn = os.path.join(self.command_dir, name.replace('-', '_') + '.py')
# 
#         if not os.path.exists(fn):
#             click.echo('error: unknown command: %s' % name)
#             sys.exit(1)
# 
#         with open(fn) as f:
#             code = compile(f.read(), fn, 'exec')
#             eval(code, ns, ns)
#         return ns['cli']
# 
#     def invoke(self, ctx):  # noqa
#         # setup logging
#         if 'verbose' in ctx.params and ctx.params['verbose']:
#             level = max(10, 40 - ctx.params['verbose'] * 10)
#             set_log_level(level)
#             verbosity(ctx.params['verbose'])
#         if 'log_file' in ctx.params and ctx.params['log_file']:
#             set_log_file(ctx.params['log_file'])
# 
#         # try running the command
#         try:
#             super(AerisCLI, self).invoke(ctx)
#         except SystemExit:
#             raise
#         except click.UsageError as e:
#             click.secho('error: %s' % e.message, err=True, fg='red')
#             click.echo(e.ctx.command.get_help(e.ctx), err=True)
#             sys.exit(e.exit_code)
#         except (ExposeTimeout, ExposeConnectionError):
#             warning('warning: expose is not available at the moment')
#         except KeyboardInterrupt:
#             logger.error('keyboard interrupt while running subcommand "%s"',
#                          ctx.invoked_subcommand, exc_info=sys.exc_info())
#             warning('\nwarning: ctrl+c pressed, aborting')
#         except:
#             log_id = None
#             if config.has('config', 'raven'):
#                 from raven import Client
#                 client = Client('requests+' + config.get('config', 'raven'))
#                 log_id = client.get_ident(client.captureException(
#                     tags={
#                         'python': sys.version,
#                         'aeriscloud': ac_version,
#                         'platform': sys.platform
#                     },
#                     extra={
#                         'user': os.environ['USER']
#                     }
#                 ))
# 
#             logger.error('uncaught exception while running subcommand "%s"',
#                          ctx.invoked_subcommand, exc_info=sys.exc_info())
#             if log_id:
#                 fatal('error: an internal exception caused "%s" '
#                       'to exit unexpectedly (log id: %s)' % (ctx.info_name,
#                                                              log_id))
#             else:
#                 fatal('error: an internal exception caused "%s" '
#                       'to exit unexpectedly' % ctx.info_name)
# 
# Path: aeriscloud/config.py
# @memoized
# def module_path():
#     return os.path.dirname(__file__)


import os
import sys
from .helpers import AerisCLI
from ..config import module_path
#!/usr/bin/env python

# Import the CLI system

cmd_help = {
    'aeris': 'Manage your local development environments',
    'cloud': 'Manage your remote servers and datacenters'
}


def get_cli(command_name):

# Path: aeriscloud/cli/helpers.py
# class AerisCLI(click.MultiCommand):
#     def __init__(self, command_dir, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         params = [
#             click.Option(
#                 param_decls=['-v', '--verbose'],
#                 count=True,
#                 help='Make commands verbose, use '
#                      'multiple time for higher verbosity'
#             ),
#             click.Option(
#                 param_decls=['--log-file'],
#                 help='When using the verbose flag, redirects '
#                      'output to this file'
#             )
#         ]
#         super(AerisCLI, self).__init__(context_settings=cs, params=params,
#                                        *args, **kwargs)
#         self.command_dir = command_dir
# 
#         no_setup = 'AC_NO_ASSISTANT' in os.environ \
#                    and os.environ['AC_NO_ASSISTANT'] == '1'
#         if not no_setup and sys.stdout.isatty() and not config.complete():
#             click.echo('''
# It seems it is the first time you are launching AerisCloud, or new
# configuration options were added since the last update. We can guide
# you through a series of questions to setup your configuration.
# ''', err=True)
#             if not click.confirm('Run configuration assistant', default=True):
#                 return
#             from .config import assistant
# 
#             assistant()
# 
#     def list_commands(self, ctx):
#         excluded = ['complete', 'test']
# 
#         rv = [filename[:-3].replace('_', '-') for filename in
#               os.listdir(self.command_dir)
#               if filename.endswith('.py') and
#               filename[:-3] not in excluded and
#               not filename.startswith('__')]
#         rv.sort()
#         return rv
# 
#     def get_command(self, ctx, name):
#         ns = {}
#         fn = os.path.join(self.command_dir, name.replace('-', '_') + '.py')
# 
#         if not os.path.exists(fn):
#             click.echo('error: unknown command: %s' % name)
#             sys.exit(1)
# 
#         with open(fn) as f:
#             code = compile(f.read(), fn, 'exec')
#             eval(code, ns, ns)
#         return ns['cli']
# 
#     def invoke(self, ctx):  # noqa
#         # setup logging
#         if 'verbose' in ctx.params and ctx.params['verbose']:
#             level = max(10, 40 - ctx.params['verbose'] * 10)
#             set_log_level(level)
#             verbosity(ctx.params['verbose'])
#         if 'log_file' in ctx.params and ctx.params['log_file']:
#             set_log_file(ctx.params['log_file'])
# 
#         # try running the command
#         try:
#             super(AerisCLI, self).invoke(ctx)
#         except SystemExit:
#             raise
#         except click.UsageError as e:
#             click.secho('error: %s' % e.message, err=True, fg='red')
#             click.echo(e.ctx.command.get_help(e.ctx), err=True)
#             sys.exit(e.exit_code)
#         except (ExposeTimeout, ExposeConnectionError):
#             warning('warning: expose is not available at the moment')
#         except KeyboardInterrupt:
#             logger.error('keyboard interrupt while running subcommand "%s"',
#                          ctx.invoked_subcommand, exc_info=sys.exc_info())
#             warning('\nwarning: ctrl+c pressed, aborting')
#         except:
#             log_id = None
#             if config.has('config', 'raven'):
#                 from raven import Client
#                 client = Client('requests+' + config.get('config', 'raven'))
#                 log_id = client.get_ident(client.captureException(
#                     tags={
#                         'python': sys.version,
#                         'aeriscloud': ac_version,
#                         'platform': sys.platform
#                     },
#                     extra={
#                         'user': os.environ['USER']
#                     }
#                 ))
# 
#             logger.error('uncaught exception while running subcommand "%s"',
#                          ctx.invoked_subcommand, exc_info=sys.exc_info())
#             if log_id:
#                 fatal('error: an internal exception caused "%s" '
#                       'to exit unexpectedly (log id: %s)' % (ctx.info_name,
#                                                              log_id))
#             else:
#                 fatal('error: an internal exception caused "%s" '
#                       'to exit unexpectedly' % ctx.info_name)
# 
# Path: aeriscloud/config.py
# @memoized
# def module_path():
#     return os.path.dirname(__file__)


# Path: aeriscloud/cli/main.py
import os
import sys
from .helpers import AerisCLI
from ..config import module_path

#!/usr/bin/env python

# Import the CLI system

cmd_help = {
    'aeris': 'Manage your local development environments',
    'cloud': 'Manage your remote servers and datacenters'
}


def get_cli(command_name):

    command_dir = os.path.join(module_path(), 'cli', command_name)