@click.command()
@click.option('--config',
    help="Path to configuration file. Default: ~/.curator/curator.yml",
    type=click.Path(exists=True), default=CONFIG_FILE
)
@click.option('--dry-run', is_flag=True, help='Do not perform any changes.')
@click.argument('action_file', type=click.Path(exists=True), nargs=1)
@click.version_option(version=__version__)
def cli(config, dry_run, action_file):
    """
    Curator for Elasticsearch indices.

    See http://elastic.co/guide/en/elasticsearch/client/curator/current
    """
    # Get config from yaml file
    yaml_config  = get_yaml(config)
    # Get default options and overwrite with any changes
    try:
        yaml_log_opts = prune_nones(yaml_config['logging'])
        log_opts      = LOGGING_DEFAULTS
        log_opts.update(yaml_log_opts)
    except __HOLE__:
        # Use the defaults if there is no logging section
        log_opts = LOGGING_DEFAULTS
    # Set up logging
    loginfo = LogInfo(log_opts)
    logging.root.addHandler(loginfo.handler)
    logging.root.setLevel(loginfo.numeric_log_level)
    logger = logging.getLogger('curator.cli')
    # Set up NullHandler() to handle nested elasticsearch.trace Logger
    # instance in elasticsearch python client
    logging.getLogger('elasticsearch.trace').addHandler(NullHandler())

    # Get default client options and overwrite with any changes
    try:
        yaml_client  = prune_nones(yaml_config['client'])
        client_args  = CLIENT_DEFAULTS
        client_args.update(yaml_client)
    except KeyError:
        logger.critical(
            'Unable to read client configuration. '
            'Please check the configuration file: {0}'.format(config)
        )
        sys.exit(1)
    test_client_options(client_args)

    # Create a client object
    client = get_client(**client_args)
    #########################################
    ### Start working on the actions here ###
    #########################################
    actions = get_yaml(action_file)['actions']
    logger.debug('Full list of actions: {0}'.format(actions))
    action_keys = sorted(list(actions.keys()))
    for idx in action_keys:
        if 'action' in actions[idx] and actions[idx]['action'] is not None:
            action = actions[idx]['action'].lower()
        else:
            raise MissingArgument('No value for "action" provided')
        logger.info('Action #{0}: {1}'.format(idx, action))
        if not 'options' in actions[idx] or \
                type(actions[idx]['options']) is not type(dict()):
            actions[idx]['options'] = OPTION_DEFAULTS
        # Assign and remove these keys from the options as the action will
        # raise an exception if they are passed as kwargs
        action_disabled = actions[idx]['options'].pop('disable_action', False)
        continue_if_exception = (
            actions[idx]['options'].pop('continue_if_exception', False))
        logger.debug(
            'continue_if_exception = {0}'.format(continue_if_exception))
        kwargs = {}
        kwargs['master_timeout'] = (
            client_args['timeout'] if client_args['timeout'] <= 300 else 300)
        kwargs['dry_run'] = dry_run

        ### Skip to next action if 'disabled'
        if action_disabled:
            logger.info(
                'Action "{0}" not performed because "disable_action" is set to '
                'True'.format(action)
            )
            continue
        ##########################
        ### Process the action ###
        ##########################
        try:
            logger.debug('TRY: actions: {0} kwargs: '
                '{1}'.format(actions[idx], kwargs)
            )
            process_action(client, actions[idx], **kwargs)
        except Exception as e:
            logger.error(
                'Failed to complete action: {0}.  {1}: '
                '{2}'.format(action, type(e), e)
            )
            if continue_if_exception:
                logger.info(
                    'Continuing execution with next action because '
                    '"continue_if_exception" is set to True for action '
                    '{0}'.format(action)
                )
            else:
                sys.exit(1)
dataset/ETHPy150Open elastic/curator/curator/cli.py/cli