# -*- coding: utf-8 -*-
"""Elastic Search Index & Search."""

import argparse
import os


def main():
    """Entry point for the esis.py script."""
    args = parse_arguments()
    print args

def valid_directory(path):
    """Directory validation."""
    if not os.path.isdir(path):
        raise argparse.ArgumentTypeError(
            '{!r} is not a valid directory'.format(path))

    if not os.access(path, os.R_OK | os.X_OK):
        raise argparse.ArgumentTypeError(
            'not enough permissions to explore {!r}'.format(path))

    return path

def parse_arguments():
    """Parse command line arguments.

    :returns: Parsed arguments
    :rtype: argparse.Namespace

    """
    parser = argparse.ArgumentParser(description=__doc__)
    subparsers = parser.add_subparsers(help='Subcommands')
    index = subparsers.add_parser('index', help='Index SQLite database files')
    index.add_argument('directory', type=valid_directory, help='Base directory')
    search = subparsers.add_parser('search', help='Search indexed data')
    search.add_argument('query', help='Search query')
    args = parser.parse_args()
    return args

if __name__ == '__main__':
    main()

@@ -82,11 +82,63 @@
 ort 
-os%0A
+logging%0Aimport os%0A%0Alogger = logging.getLogger(__name__)
 %0A%0Ade
@@ -230,18 +230,255 @@
     
-print args
+args.func(args)%0A%0Adef index(args):%0A    %22%22%22Index database information into elasticsearch.%22%22%22%0A    logger.debug('Indexing %25r...', args.directory)%0A%0Adef search(args):%0A    %22%22%22Send query to elasticsearch.%22%22%22%0A    logger.debug('Searching %25r...', args.query)
 %0A%0Ade
@@ -1099,16 +1099,23 @@
    index
+_parser
  = subpa
@@ -1185,16 +1185,23 @@
    index
+_parser
 .add_arg
@@ -1268,22 +1268,71 @@
 y')%0A    
-search
+index_parser.set_defaults(func=index)%0A    search_parser
  = subpa
@@ -1396,16 +1396,23 @@
   search
+_parser
 .add_arg
@@ -1443,24 +1443,68 @@
 rch query')%0A
+    search_parser.set_defaults(func=search)%0A
     args = p

Add handlers for the index/search subcommands