Extracts the name space and the command name of the given command token.

    :param cmd_token: The command token
    :return: The extracted (name space, command) tuple
974649
def _split_ns_command(cmd_token):
    
    namespace = None
    cmd_split = cmd_token.split(".", 1)
    if len(cmd_split) == 1:
        # No name space given
        command = cmd_split[0]
    else:
        # Got a name space and a command
        namespace = cmd_split[0]
        command = cmd_split[1]

    if not namespace:
        # No name space given: given an empty one
        namespace = ""

    # Use lower case values only
    return namespace.lower(), command.lower()
718956
private function getCommandAliasesText(Command $command): string
    {
        $text = '';
        $aliases = $command->getAliases();

        if ($aliases) {
            $text = '['.implode('|', $aliases).'] ';
        }

        return $text;
    }
428050
def read_token(fd):
    
    out = ''
    # Skip initial whitespace.

    while 1:
        ch = fd.read(1)
        if ch.isspace(): continue
        elif len(ch) == 0: return out
        else: break

    while not ch.isspace():
        out = out + ch
        ch = fd.read(1)
        if len(ch) == 0: break

    return out
58445
def show_help(command_name: str = None, raw_args: str = '') -> Response:
    

    response = Response()

    cmds = fetch()
    if command_name and command_name in cmds:
        parser, result = parse.get_parser(
            cmds[command_name],
            parse.explode_line(raw_args),
            dict()
        )

        if parser is not None:
            out = parser.format_help()
            return response.notify(
                kind='INFO',
                code='COMMAND_DESCRIPTION'
            ).kernel(
                commands=out
            ).console(
                out,
                whitespace=1
            ).response

    environ.log_header('Available Commands')
    response.consume(print_module_help())

    return response.fail(
        code='NO_SUCH_COMMAND',
        message='Failed to show command help for "{}"'.format(command_name)
    ).console(
        """
        For more information on the various commands, enter help on the
        specific command:

            help [COMMAND]
        """,
        whitespace_bottom=1
    ).response
17962
function splitCommand(line) {
    // Make sure we get the same results irrespective of leading/trailing spaces
    var match = line.match(TOKEN_WHITESPACE);
    if (!match) {
        return {
            name: line.toUpperCase(),
            rest: ''
        };
    }
    var name = line.substr(0, match.index).toUpperCase();
    var rest = line.substr(match.index + match[0].length);

    return {
        name: name,
        rest: rest
    };
}
83536
def command_objects(names=self.commands, command_array=Boson.commands)
      command_array.select {|e| names.include?(e.name) && e.lib == self.name }
    end
489369
protected function getCommand($cmd, $tokens)
    {
        return Template::parse($cmd, $tokens, '%%', '%%', Template::FLAG_RECURSIVE | Template::FLAG_EMPTY_MISSING);
    }
980664
def _get_command_and_argv(argv):
    # type: (typing.List[str]) -> typing.Tuple[str, typing.List[str]]
    
    command_name = argv[0]
    if not command_name:
        argv = argv[1:]
    elif command_name == settings.command:
        argv.remove(command_name)
    return command_name, argv
1325659
def get_ns_command(self, cmd_name):
        
        namespace, command = _split_ns_command(cmd_name)
        if not namespace:
            # Name space not given, look for the command
            spaces = self.__find_command_ns(command)
            if not spaces:
                # Unknown command
                raise ValueError("Unknown command {0}".format(command))
            elif len(spaces) > 1:
                # Multiple possibilities
                if spaces[0] == DEFAULT_NAMESPACE:
                    # Default name space has priority
                    namespace = DEFAULT_NAMESPACE

                else:
                    # Ambiguous name
                    raise ValueError(
                        "Multiple name spaces for command '{0}': {1}".format(
                            command, ", ".join(sorted(spaces))
                        )
                    )
            else:
                # Use the found name space
                namespace = spaces[0]

        # Command found
        return namespace, command
787414
def parse_command(bot: NoneBot,
                  cmd_string: str) -> Tuple[Optional[Command], Optional[str]]:
    
    logger.debug(f'Parsing command: {cmd_string}')

    matched_start = None
    for start in bot.config.COMMAND_START:
        # loop through COMMAND_START to find the longest matched start
        curr_matched_start = None
        if isinstance(start, type(re.compile(''))):
            m = start.search(cmd_string)
            if m and m.start(0) == 0:
                curr_matched_start = m.group(0)
        elif isinstance(start, str):
            if cmd_string.startswith(start):
                curr_matched_start = start

        if curr_matched_start is not None and \
                (matched_start is None or
                 len(curr_matched_start) > len(matched_start)):
            # a longer start, use it
            matched_start = curr_matched_start

    if matched_start is None:
        # it's not a command
        logger.debug('It\'s not a command')
        return None, None

    logger.debug(f'Matched command start: '
                 f'{matched_start}{"(empty)" if not matched_start else ""}')
    full_command = cmd_string[len(matched_start):].lstrip()

    if not full_command:
        # command is empty
        return None, None

    cmd_name_text, *cmd_remained = full_command.split(maxsplit=1)
    cmd_name = _aliases.get(cmd_name_text)

    if not cmd_name:
        for sep in bot.config.COMMAND_SEP:
            # loop through COMMAND_SEP to find the most optimized split
            curr_cmd_name = None
            if isinstance(sep, type(re.compile(''))):
                curr_cmd_name = tuple(sep.split(cmd_name_text))
            elif isinstance(sep, str):
                curr_cmd_name = tuple(cmd_name_text.split(sep))

            if curr_cmd_name is not None and \
                    (not cmd_name or len(curr_cmd_name) > len(cmd_name)):
                # a more optimized split, use it
                cmd_name = curr_cmd_name

        if not cmd_name:
            cmd_name = (cmd_name_text,)

    logger.debug(f'Split command name: {cmd_name}')
    cmd = _find_command(cmd_name)
    if not cmd:
        logger.debug(f'Command {cmd_name} not found')
        return None, None

    logger.debug(f'Command {cmd.name} found, function: {cmd.func}')
    return cmd, ''.join(cmd_remained)
245761
def match(self, *command_tokens, **command_env):
		
		mutated_command_tokens = self.mutate_command_tokens(*command_tokens)
		if mutated_command_tokens is None:
			return False
		return self.selector().select(*mutated_command_tokens, **command_env) is not None
774895
def __cmd_to_func(cmd):
    
    fiss_module = sys.modules[__name__]
    # Returns None if string is not a recognized FISS command
    func = getattr(fiss_module, cmd, None)
    if func and not hasattr(func, 'fiss_cmd'):
        func = None
    return func
761883
def decode(cls, command_str):
        

        name, _, arg = command_str.partition(" ")

        args = []

        if len(arg) > 0:
            if arg[0] != '{' or arg[-1] != '}':
                raise DataError("Invalid command, argument is not contained in { and }", arg=arg, cmd=name)

            arg = arg[1:-1]
            args = arg.split(",")

        proc = []

        for arg in args:
            if arg.startswith("hex:"):
                arg = unhexlify(arg[4:]).decode('utf-8')

            proc.append(arg)

        return Command(name, proc)
1294809
function parseNameVal(cmd) {
    // This is kind of tricky because we need to support the old
    // variant:   KEY name value
    // as well as the new one:    KEY name=value ...
    // The trigger to know which one is being used will be whether we hit
    // a space or = first.  space ==> old, "=" ==> new
    var word;
    var words = parseWords(cmd.rest);

    cmd.args = {};

    if (words.length === 0) {
        cmd.error = 'No KEY name value, or KEY name=value arguments found';
        return false;
    }

    if (words[0].indexOf('=') == -1) {
        // Old format (KEY name value)
        var strs = cmd.rest.split(TOKEN_WHITESPACE);
        if (strs.length < 2) {
            cmd.error = cmd.name + ' must have two arguments, got ' + cmd.rest;
            return false;
        }

        // Convert to new style key:value map.
        cmd.args[strs[0]] = strs.slice(1).join(' ');

    } else {
        // New format (KEY name=value ...)
        var i;
        for (i = 0; i < words.length; i++) {
            word = words[i];
            if (word.indexOf('=') == -1) {
                cmd.error = 'Syntax error - can\'t find = in ' + word + '. Must be of the form: name=value';
                return false;
            }
            var parts = word.split('=');
            cmd.args[parts[0]] = parts.slice(1).join('=');
        }
    }

    return true;
}
1308358
def get_cmd_tuple_list(self):
    

    # pattern to find DAGman macros
    pat = re.compile(r'\$\((.+)\)')
    argpat = re.compile(r'\d+')

    # first parse the options and replace macros with values
    options = self.job().get_opts()
    macros = self.get_opts()

    cmd_list = []

    for k in options:
      val = options[k]
      m = pat.match(val)
      if m:
        key = m.group(1)
        value = macros[key]

        cmd_list.append(("--%s" % k, str(value)))
      else:
        cmd_list.append(("--%s" % k, str(val)))

    # second parse the short options and replace macros with values
    options = self.job().get_short_opts()

    for k in options:
      val = options[k]
      m = pat.match(val)
      if m:
        key = m.group(1)
        value = macros[key]

        cmd_list.append(("-%s" % k, str(value)))
      else:
        cmd_list.append(("-%s" % k, str(val)))

    # lastly parse the arguments and replace macros with values
    args = self.job().get_args()
    macros = self.get_args()

    for a in args:
      m = pat.match(a)
      if m:
        arg_index = int(argpat.findall(a)[0])
        try:
          cmd_list.append(("%s" % macros[arg_index], ""))
        except IndexError:
          cmd_list.append("")
      else:
        cmd_list.append(("%s" % a, ""))

    return cmd_list
172580
def _command_and_args(tokens: List[str]) -> Tuple[str, str]:
        
        command = ''
        args = ''

        if tokens:
            command = tokens[0]

        if len(tokens) > 1:
            args = ' '.join(tokens[1:])

        return command, args
523010
function getCommand(commandName) {
    return _.find(commands, function (command) {
      return _.includes(command.aliases, commandName);
    });
  }