Beispiel #1
0
def completer(text, state):
    from fbcli.cli import (
        COMMANDS, ALIASES, LAST_SEARCH, FBShortCase, FBPerson, CURRENT_CASE)

    line = readline.get_line_buffer()
    cmd = line.split()[0] if line else None

    all_options = []
    if cmd == 'attachment':
        if CURRENT_CASE:
            all_options += [str(a.id) for a in CURRENT_CASE.attachments]
    elif cmd == 'assign':
        all_options += [person.fullname for person in FBPerson.CACHE]
    else:
        all_options += list(COMMANDS.keys())
        all_options += list(ALIASES.keys())
        all_options += [str(case.id) for case in FBShortCase.HISTORY]
        if LAST_SEARCH:
            all_options += [str(case.id) for case in LAST_SEARCH.shortcases]

    options = [x for x in all_options if text in x]
    try:
        return options[state]
    except IndexError:
        return None
Beispiel #2
0
def completer(text, state):
    from fbcli.cli import (COMMANDS, ALIASES, LAST_SEARCH, FBShortCase,
                           FBPerson, CURRENT_CASE)

    # READLINE_LOGGER.info('text=%s state=%s', text, state)
    line = readline.get_line_buffer()

    cmd = line.split()[0] if line else None
    rest = line.split()[1:] if line else None
    if line and not line.endswith(' '):
        rest = rest[:-1]

    if rest:
        text = ' '.join(rest) + ' ' + text

    # READLINE_LOGGER.info(
    #     'cmd=%s line=%s rest=%s text=%s', cmd, line, rest, text)

    all_options = []
    if cmd == 'attachment' and text != 'attachment':
        if CURRENT_CASE:
            all_options += [str(a.id) for a in CURRENT_CASE.attachments]
    elif cmd in ('assign', 'notify'):
        all_options += [person.fullname for person in FBPerson.CACHE]
    else:
        all_options += list(COMMANDS.keys())
        all_options += list(ALIASES.keys())
        all_options += [str(case.id) for case in FBShortCase.HISTORY]
Beispiel #3
0
def completer(text, state):
    from fbcli.cli import COMMANDS, LAST_SEARCH, FBShortCase, FBPerson

    all_options = COMMANDS.keys()
    all_options += [str(case.id) for case in FBShortCase.HISTORY]
    all_options += [person.fullname for person in FBPerson.CACHE]
    if LAST_SEARCH:
        all_options += [str(case.id) for case in LAST_SEARCH.shortcases]

    options = [x for x in all_options if x.startswith(text)]
    try:
        return options[state]
    except IndexError:
        return None