<commit_before>import os
import posixpath
import sys
from functools import partial

import docopt
import six

import dcoscli
from dcos import cmds, config, emitting, mesos, util
from dcos.errors import DCOSException, DCOSHTTPException, DefaultError
from dcoscli import log, tables
from dcoscli import metrics
from dcoscli.subcommand import default_command_info, default_doc
from dcoscli.util import decorate_docopt_usage

logger = util.get_logger(__name__)
emitter = emitting.FlatEmitter()


def main(argv):
    try:
        return _main(argv)
    except DCOSException as e:
        emitter.publish(e)
        return 1


def docopt_wrapper(usage, real_usage, **keywords):
    """ A wrapper around the real docopt parser.
    Redirects a failed command to /dev/null and prints the proper
    real_usage message, instead of just the usage string from usage.

    :param usage: The simplified usage string to parse
    :type usage: str
    :param real_usage: The original usage string to parse
    :type real_usage: str
    :param keywords: The keyword arguments to pass to docopt
    :type keywords: dict
    :returns: The parsed arguments
    :rtype: dict
    """

    base_subcommand = keywords.pop('base_subcommand')
    subcommand = keywords.pop('subcommand')

    try:
        stdout = sys.stdout

        # We run docopt twice (once with the real usage string and
        # once with the modified usage string) in order to populate
        # the 'real' arguments properly.
        with open(os.devnull, 'w') as nullfile:
            sys.stdout = nullfile
            real_arguments = docopt.docopt(
                real_usage,
                argv=[base_subcommand])
            arguments = docopt.docopt(
                usage,
                **keywords)
            sys.stdout = stdout

        real_arguments.update(arguments)
        real_arguments[subcommand] = True
        return real_arguments

    except docopt.DocoptExit:
        sys.stdout = stdout
        print(real_usage.strip(), file=sys.stderr)
        sys.exit(1)

    except SystemExit:
        sys.stdout = stdout

        if "argv" in keywords and any(h in ("-h", "--help")
                                      for h in keywords["argv"]):
            print(real_usage.strip())
        elif "version" in keywords and any(v in ("--version")
                                           for v in keywords["argv"]):
            print(keywords["version"].strip())

        sys.exit()


@decorate_docopt_usage
def _main(argv):
    """The main function for the 'task' subcommand"""

    # We must special case the 'dcos task exec' subcommand in order to
    # allow us to pass arguments to docopt in a more user-friendly
    # manner. Specifically, we need to be able to to pass arguments
    # beginning with "-" to the command we are trying to launch with
    # 'exec' without docopt trying to match them to a named parameter
    # for the 'dcos' command itself.
    if len(argv) > 1 and argv[1] == "exec":
        args = docopt_wrapper(
            default_doc("task_exec"),
            default_doc("task"),
            argv=argv[2:],
            version="dcos-task version {}".format(dcoscli.version),
            options_first=True,
            base_subcommand="task",
            subcommand="exec")
    else:
        args = docopt.docopt(
            default_doc("task"),
            argv=argv,
            version="dcos-task version {}".format(dcoscli.version))

    return cmds.execute(_cmds(), args)


def _cmds():<commit_msg>Fix typo in comment of the task subcommand's main function (#1022)<commit_after>import os
import posixpath
import sys
from functools import partial

import docopt
import six

import dcoscli
from dcos import cmds, config, emitting, mesos, util
from dcos.errors import DCOSException, DCOSHTTPException, DefaultError
from dcoscli import log, tables
from dcoscli import metrics
from dcoscli.subcommand import default_command_info, default_doc
from dcoscli.util import decorate_docopt_usage

logger = util.get_logger(__name__)
emitter = emitting.FlatEmitter()


def main(argv):
    try:
        return _main(argv)
    except DCOSException as e:
        emitter.publish(e)
        return 1


def docopt_wrapper(usage, real_usage, **keywords):
    """ A wrapper around the real docopt parser.
    Redirects a failed command to /dev/null and prints the proper
    real_usage message, instead of just the usage string from usage.

    :param usage: The simplified usage string to parse
    :type usage: str
    :param real_usage: The original usage string to parse
    :type real_usage: str
    :param keywords: The keyword arguments to pass to docopt
    :type keywords: dict
    :returns: The parsed arguments
    :rtype: dict
    """

    base_subcommand = keywords.pop('base_subcommand')
    subcommand = keywords.pop('subcommand')

    try:
        stdout = sys.stdout

        # We run docopt twice (once with the real usage string and
        # once with the modified usage string) in order to populate
        # the 'real' arguments properly.
        with open(os.devnull, 'w') as nullfile:
            sys.stdout = nullfile
            real_arguments = docopt.docopt(
                real_usage,
                argv=[base_subcommand])
            arguments = docopt.docopt(
                usage,
                **keywords)
            sys.stdout = stdout

        real_arguments.update(arguments)
        real_arguments[subcommand] = True
        return real_arguments

    except docopt.DocoptExit:
        sys.stdout = stdout
        print(real_usage.strip(), file=sys.stderr)
        sys.exit(1)

    except SystemExit:
        sys.stdout = stdout

        if "argv" in keywords and any(h in ("-h", "--help")
                                      for h in keywords["argv"]):
            print(real_usage.strip())
        elif "version" in keywords and any(v in ("--version")
                                           for v in keywords["argv"]):
            print(keywords["version"].strip())

        sys.exit()


@decorate_docopt_usage
def _main(argv):
    """The main function for the 'task' subcommand"""

    # We must special case the 'dcos task exec' subcommand in order to
    # allow us to pass arguments to docopt in a more user-friendly
    # manner. Specifically, we need to be able to pass arguments
    # beginning with "-" to the command we are trying to launch with
    # 'exec' without docopt trying to match them to a named parameter
    # for the 'dcos' command itself.
    if len(argv) > 1 and argv[1] == "exec":
        args = docopt_wrapper(
            default_doc("task_exec"),
            default_doc("task"),
            argv=argv[2:],
            version="dcos-task version {}".format(dcoscli.version),
            options_first=True,
            base_subcommand="task",
            subcommand="exec")
    else:
        args = docopt.docopt(
            default_doc("task"),
            argv=argv,
            version="dcos-task version {}".format(dcoscli.version))

    return cmds.execute(_cmds(), args)


def _cmds():
{'fraction_non_alphanumeric': 0.08560090702947845, 'fraction_numerical': 0.001984126984126984, 'mean_word_length': 2.3862763915547025, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6055960', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1898, 'n_words': 666}