Пример #1
0
def match(command):
    is_proper_command = ('brew' in command.script and
                         'Unknown command' in command.stderr)

    if is_proper_command:
        broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
                                command.stderr)[0]
        return bool(get_closest(broken_cmd, _brew_commands()))
    return False
Пример #2
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file, get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
Пример #3
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file,
                                       get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}',
                          '{}').format(missing_file, command.script)
Пример #4
0
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd,
                              stash_commands,
                              fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
Пример #5
0
def get_new_command(command):
    old_command = command.script_parts[0]

    # One from history:
    already_used = get_closest(
        old_command, _get_used_executables(command),
        fallback_to_first=False)
    if already_used:
        new_cmds = [already_used]
    else:
        new_cmds = []

    # Other from all executables:
    new_cmds += [cmd for cmd in get_close_matches(old_command,
                                                  get_all_executables())
                 if cmd not in new_cmds]

    return [' '.join([new_command] + command.script_parts[1:])
            for new_command in new_cmds]
Пример #6
0
 def test_without_fallback(self):
     assert get_closest('st', ['status', 'reset'],
                        fallback_to_first=False) is None
Пример #7
0
 def test_when_cant_match(self):
     assert 'status' == get_closest('st', ['status', 'reset'])
Пример #8
0
 def test_when_can_match(self):
     assert 'branch' == get_closest('brnch', ['branch', 'status'])
Пример #9
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
Пример #10
0
def get_new_command(command):
    script = command.script_parts[:]
    possibilities = extract_possibilities(command)
    script[1] = get_closest(script[1], possibilities)
    return ' '.join(script)
Пример #11
0
 def test_without_fallback(self):
     assert get_closest('st', ['status', 'reset'],
                        fallback_to_first=False) is None
Пример #12
0
 def test_when_cant_match(self):
     assert 'status' == get_closest('st', ['status', 'reset'])
Пример #13
0
 def test_when_can_match(self):
     assert 'branch' == get_closest('brnch', ['branch', 'status'])
Пример #14
0
def _get_similar_formula(formula_name):
    return get_closest(formula_name, _get_formulas(), 1, 0.85)
Пример #15
0
def get_new_command(command):
    return get_closest(command.script,
                       get_valid_history_without_current(command))
Пример #16
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)