<commit_before>"""Entry points for exported scripts."""

import argparse
import logging
import os.path
import sys
import traceback

import pkg_resources

from tablesnap.endpoints import endpoints

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Sub Commands take the command line args and call the function to do the 
# work. Sub commands are retrieved from the ``tablesnap.sub_commands`` entry 
# point using :mod:`pkg_resources`, see :func:`arg_parser`.
# The ones here are global.

def execute_help(args):
    """Global sub command than prints the help for a sub command.
    """
    temp_parser = arg_parser()
    if args.command:
        temp_parser.parse_args([args.command, "-h"])
    return temp_parser.format_help()
    
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 
def arg_parser():
    """Builds a :class:`argparse.ArgumentParser` for the ``tablesnap`` 
    command. 
    
    The ``tablesnap`` script uses a sub command structure, like svn or 
    git. For example::
    
        tablesnap snap-s3 <watch-dir> <bucket-name>
        
    * ``tablesnap`` is the script name. 
    * ``snap-s3`` is the sub command
    * ``watch-dir`` is a positional argument common to all snap commands. 
    * ``bucket-name`` is positional argument for the ``snap-s3`` 
    command.
    """
    
    # This is the main parser that the script entry point uses.
    main_parser = argparse.ArgumentParser(
        description="tablesnap - snap, slurp, purge", 
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    
    # say we have sub commands
    sub_parsers = main_parser.add_subparsers(title="Commands", 
        description="Commands to help you snap, slurp, purge.")

    # Start adding sub commands
    # use set_default() to specify a function to call for each sub command.

    # Global / static sub commands
    # Show help for a sub command.
    parser = sub_parsers.add_parser("help", help="Get help.")
    parser.set_defaults(func=execute_help)
    parser.add_argument('command', type=str, default="", nargs="?",
        help='Command to print help for.')
    
    for entry_point in pkg_resources.iter_entry_points(
        "tablesnap.sub_commands"):
        
        # Load the class and add it's parser
        entry_point.load().add_sub_parser(sub_parsers)

    endpoint_names = []
    # Add all of the endpoints
    for entry_point in pkg_resources.iter_entry_points("tablesnap.endpoints"):
        
        # Load the class and add it's parser
        endpoint_class = entry_point.load()
        endpoint_class.add_arg_group(main_parser)
        endpoint_names.append(endpoint_class.name)

    # Global Configuration
    main_parser.add_argument("--endpoint", default="local", 
        choices=endpoint_names, 
        help="Name of the endpoint to use for backup and restore.")

    main_parser.add_argument("--log-level", default="DEBUG", 
        dest="log_level", 
        choices=["FATAL", "CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"],
        help="Logging level.")
    main_parser.add_argument("--log-file", default="./tablesnap.log", 
        dest="log_file", <commit_msg>change log level<commit_after>"""Entry points for exported scripts."""

import argparse
import logging
import os.path
import sys
import traceback

import pkg_resources

from tablesnap.endpoints import endpoints

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Sub Commands take the command line args and call the function to do the 
# work. Sub commands are retrieved from the ``tablesnap.sub_commands`` entry 
# point using :mod:`pkg_resources`, see :func:`arg_parser`.
# The ones here are global.

def execute_help(args):
    """Global sub command than prints the help for a sub command.
    """
    temp_parser = arg_parser()
    if args.command:
        temp_parser.parse_args([args.command, "-h"])
    return temp_parser.format_help()
    
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 
def arg_parser():
    """Builds a :class:`argparse.ArgumentParser` for the ``tablesnap`` 
    command. 
    
    The ``tablesnap`` script uses a sub command structure, like svn or 
    git. For example::
    
        tablesnap snap-s3 <watch-dir> <bucket-name>
        
    * ``tablesnap`` is the script name. 
    * ``snap-s3`` is the sub command
    * ``watch-dir`` is a positional argument common to all snap commands. 
    * ``bucket-name`` is positional argument for the ``snap-s3`` 
    command.
    """
    
    # This is the main parser that the script entry point uses.
    main_parser = argparse.ArgumentParser(
        description="tablesnap - snap, slurp, purge", 
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    
    # say we have sub commands
    sub_parsers = main_parser.add_subparsers(title="Commands", 
        description="Commands to help you snap, slurp, purge.")

    # Start adding sub commands
    # use set_default() to specify a function to call for each sub command.

    # Global / static sub commands
    # Show help for a sub command.
    parser = sub_parsers.add_parser("help", help="Get help.")
    parser.set_defaults(func=execute_help)
    parser.add_argument('command', type=str, default="", nargs="?",
        help='Command to print help for.')
    
    for entry_point in pkg_resources.iter_entry_points(
        "tablesnap.sub_commands"):
        
        # Load the class and add it's parser
        entry_point.load().add_sub_parser(sub_parsers)

    endpoint_names = []
    # Add all of the endpoints
    for entry_point in pkg_resources.iter_entry_points("tablesnap.endpoints"):
        
        # Load the class and add it's parser
        endpoint_class = entry_point.load()
        endpoint_class.add_arg_group(main_parser)
        endpoint_names.append(endpoint_class.name)

    # Global Configuration
    main_parser.add_argument("--endpoint", default="local", 
        choices=endpoint_names, 
        help="Name of the endpoint to use for backup and restore.")

    main_parser.add_argument("--log-level", default="INFO", 
        dest="log_level", 
        choices=["FATAL", "CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"],
        help="Logging level.")
    main_parser.add_argument("--log-file", default="./tablesnap.log", 
        dest="log_file", 
{'fraction_non_alphanumeric': 0.14946507237256135, 'fraction_numerical': 0.0009439899307740718, 'mean_word_length': 3.309830508474576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1961315', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1769, 'n_words': 532}