author Kyle Machulis <>
Fri, 29 Mar 2013 15:12:58 -0700
changeset 137136 0db3022ca2e6bec95897850f797f078464a7f529
parent 136615 c9bf19d37fe084efd285fb985784a0d92a02f978
child 142272 dac8cb02fd216d408a9da4329b9d0ee1cb940b7a
permissions -rw-r--r--
Backout for changeset 03452b187c14 (Bug 855465) due to bustage on a CLOSED TREE; r=qdot

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

from __future__ import unicode_literals

from collections import namedtuple

# Holds mach run-time state so it can easily be passed to command providers.
CommandContext = namedtuple('CommandContext', ['topdir', 'cwd',
    'settings', 'log_manager', 'commands'])

class MethodHandler(object):
    """Describes a Python method that implements a mach command.

    Instances of these are produced by mach when it processes classes
    defining mach commands.
    __slots__ = (
        # The Python class providing the command. This is the class type not
        # an instance of the class. Mach will instantiate a new instance of
        # the class if the command is executed.

        # Whether the __init__ method of the class should receive a mach
        # context instance. This should only affect the mach driver and how
        # it instantiates classes.

        # The name of the method providing the command. In other words, this
        # is the str name of the attribute on the class type corresponding to
        # the name of the function.

        # The argparse subparser for this command's arguments.

        # Arguments passed to add_parser() on the main mach subparser. This is
        # a 2-tuple of positional and named arguments, respectively.

        # Arguments added to this command's parser. This is a 2-tuple of
        # positional and named arguments, respectively.

    def __init__(self, cls, method, parser_args, arguments=None,

        self.cls = cls
        self.method = method
        self.parser_args = parser_args
        self.arguments = arguments or []
        self.pass_context = pass_context