Exemplo n.º 1
0
def show_help(command_name: str = None, raw_args: str = '') -> Response:
    """ Prints the basic command help to the console """

    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
Exemplo n.º 2
0
def autocomplete(command_name: str, prefix: str, line: str, begin_index: int,
                 end_index: int):
    """

    :param command_name:
    :param prefix:
    :param line:
    :param begin_index:
    :param end_index:
    :return:
    """

    cmds = fetch()
    if command_name not in cmds:
        return []

    parts = parse.explode_line(line)[1:]
    if line.endswith(' '):
        parts.append('')

    try:
        module = cmds[command_name]
        if hasattr(module, 'autocomplete'):
            out = getattr(module, 'autocomplete')(prefix, line, parts)
            if out is not None:
                return out
    except Exception as err:
        environ.log(message='[ERROR] Autocomplete Failed: "{}"'.format(err),
                    whitespace=1)

    return []
Exemplo n.º 3
0
    def test_explode_line(self):
        """
        """

        src = 'run "my name" --force --help --test 1'
        parts = parse.explode_line(src)

        self.assertEqual(len(parts), 6)
Exemplo n.º 4
0
    def test_explode_line(self):
        """
        """

        src = 'run "my name" --force --help --test 1'
        parts = parse.explode_line(src)

        self.assertEqual(len(parts), 6)