# 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 http://mozilla.org/MPL/2.0/.
import time from copy import deepcopy from cProfile import Profile from pathlib import Path
from .base import MachError
INVALID_COMMAND_CONTEXT = r"""
It looks like you tried to run a mach command from an invalid context. The %s
command failed to meet the following conditions: %s
Run |mach help| to show a list of all commands available to the current context. """.lstrip()
class MachRegistrar: """Container for mach command and config providers."""
@classmethod def _fail_conditions(_, handler, instance):
fail_conditions = [] if handler.conditions: for c in handler.conditions: ifnot c(instance):
fail_conditions.append(c)
def dispatch(self, name, context, argv=None, subcommand=None, **kwargs): """Dispatch/run a command.
Commands can use this to call other commands. """ from mach.command_util import load_command_module_from_command_name
handler = self.command_handlers.get(name)
ifnot handler:
load_command_module_from_command_name(name, context.topdir)
handler = self.command_handlers.get(name) ifnot handler: raise MachError(
f"Mach was not able to load the module for the '{name}' command."
)
if subcommand:
handler = handler.subcommand_handlers[subcommand]
if handler.parser:
parser = handler.parser
# save and restore existing defaults and actions so **kwargs don't # persist across subsequent invocations of Registrar.dispatch()
old_defaults = deepcopy(parser._defaults)
old_actions = deepcopy(parser._actions)
if unknown: if subcommand:
name = "{} {}".format(name, subcommand)
parser.error( "unrecognized arguments for {}: {}".format(
name, ", ".join(["'{}'".format(arg) for arg in unknown])
)
)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.