コード例 #1
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git",
        command.output,
    )[0]
    closest_branch = utils.get_closest(missing_file,
                                       get_branches(),
                                       fallback_to_first=False)

    new_commands = []

    if closest_branch:
        new_commands.append(
            replace_argument(command.script, missing_file, closest_branch))
    if command.script_parts[1] == "checkout":
        new_commands.append(
            replace_argument(command.script, "checkout", "checkout -b"))

    if not new_commands:
        new_commands.append(
            shell.and_("git branch {}", "{}").format(missing_file,
                                                     command.script))

    return new_commands
コード例 #2
0
ファイル: git_checkout.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.output)[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)
    elif command.script_parts[1] == 'checkout':
        return replace_argument(command.script, 'checkout', 'checkout -b')
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
コード例 #3
0
ファイル: git_checkout.py プロジェクト: zhoudawang233/thefuck
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git", command.output)[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)
    elif command.script_parts[1] == 'checkout':
        return replace_argument(command.script, 'checkout', 'checkout -b')
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
コード例 #4
0
def get_new_command(command):
    destination = _get_destination(command)
    paths = _get_all_absolute_paths_from_history(command)

    return [replace_argument(command.script, destination, path)
            for path in paths if path.endswith(destination)
            and Path(path).expanduser().exists()]
コード例 #5
0
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)
    else:
        # the only non-qualified permitted options are the repository and refspec; git's
        # suggestion include them, so they won't be lost, but would be duplicated otherwise.
        push_idx = command_parts.index('push') + 1
        while len(command_parts) > push_idx and command_parts[
                len(command_parts) - 1][0] != '-':
            command_parts.pop(len(command_parts) - 1)

    arguments = re.findall(r'git push (.*)',
                           command.output)[0].replace("'", r"\'").strip()
    return replace_argument(" ".join(command_parts), 'push',
                            'push {}'.format(arguments))
コード例 #6
0
def get_new_command(command):
    unknown_branch = re.findall(r"merge: (.+) - not something we can merge",
                                command.output)[0]
    remote_branch = re.findall(r"Did you mean this\?\n\t([^\n]+)",
                               command.output)[0]

    return replace_argument(command.script, unknown_branch, remote_branch)
コード例 #7
0
def get_new_command(command):
    for idx, arg in enumerate(command.script_parts[1:]):
        # allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args
        # for example 'adb -s 111 logcat' or 'adb -e logcat'
        if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H', '-P', '-L'):
            adb_cmd = get_closest(arg, _ADB_COMMANDS)
            return replace_argument(command.script, arg, adb_cmd)
コード例 #8
0
def get_new_command(command):
    broken = re.findall(r"pyenv: no such command `([^']*)'", command.output)[0]
    matched = [
        replace_argument(command.script, broken, common_typo)
        for common_typo in COMMON_TYPOS.get(broken, [])
    ]
    matched.extend(replace_command(command, broken, get_pyenv_commands()))
    return matched
コード例 #9
0
def get_new_command(command):
    for idx, arg in enumerate(command.script_parts[1:]):
        # allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args
        # for example 'adb -s 111 logcat' or 'adb -e logcat'
        if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H',
                                                                   '-P', '-L'):
            adb_cmd = get_closest(arg, _ADB_COMMANDS)
            return replace_argument(command.script, arg, adb_cmd)
コード例 #10
0
def get_new_command(command):
    misspelled_task = regex.findall(command.output)[0]
    if misspelled_task in npm_commands:
        yarn_command = npm_commands[misspelled_task]
        return replace_argument(command.script, misspelled_task, yarn_command)
    else:
        tasks = _get_all_tasks()
        return replace_command(command, misspelled_task, tasks)
コード例 #11
0
def get_new_command(command):
    broken_cmd = re.findall(r"Command \"([^']*)\" is not defined",
                            command.output)[0]
    new_cmd = re.findall(r"Did you mean this\?[^\n]*\n\s*([^\n]*)",
                         command.output)
    if not new_cmd:
        new_cmd = re.findall(r"Did you mean one of these\?[^\n]*\n\s*([^\n]*)",
                             command.output)
    return replace_argument(command.script, broken_cmd, new_cmd[0].strip())
コード例 #12
0
def get_new_command(command):
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]

    app = command.script_parts[0]
    app_commands = cache(which(app))(get_app_commands)(app)
    matched.extend(replace_command(command, broken, app_commands))
    return matched
コード例 #13
0
def get_new_command(command, settings):
    cmd = re.match(r"ambiguous command: (.*), could be: (.*)", command.stderr)

    old_cmd = cmd.group(1)
    suggestions = [cmd.strip() for cmd in cmd.group(2).split(",")]

    new_cmd = get_closest(old_cmd, suggestions)

    return replace_argument(command.script, old_cmd, new_cmd)
コード例 #14
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)
コード例 #15
0
def get_new_command(command):
    if "install" in command.script_parts and "composer require" in command.output.lower():
        broken_cmd, new_cmd = "install", "require"
    else:
        broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0]
        new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output)
        if not new_cmd:
            new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output)
        new_cmd = new_cmd[0].strip()
    return replace_argument(command.script, broken_cmd, new_cmd)
コード例 #16
0
ファイル: git_fix_stash.py プロジェクト: roth1002/thefuck
def get_new_command(command, settings):
    stash_cmd = command.script.split()[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.split()
        cmd.insert(2, 'save')
        return ' '.join(cmd)
コード例 #17
0
ファイル: git_checkout.py プロジェクト: roth1002/thefuck
def get_new_command(command, settings):
    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 shells.and_('git branch {}', '{}').format(
            missing_file, command.script)
コード例 #18
0
def get_new_command(command, settings):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        "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 shells.and_('git branch {}', '{}').format(
            missing_file, command.script)
コード例 #19
0
ファイル: git_push.py プロジェクト: Googulator/thefuck
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)

    push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
    return replace_argument(" ".join(command_parts), 'push', push_upstream)
コード例 #20
0
ファイル: git_push.py プロジェクト: mengdaya/fuckshell
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)

    push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
    return replace_argument(" ".join(command_parts), 'push', push_upstream)
コード例 #21
0
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)

    arguments = re.findall(r'git push (.*)', command.stderr)[0].strip()
    return replace_argument(" ".join(command_parts), 'push',
                            'push {}'.format(arguments))
コード例 #22
0
ファイル: git_push.py プロジェクト: yongbinfeng/thefuck
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)

    arguments = re.findall(r'git push (.*)', command.output)[0].strip()
    return replace_argument(" ".join(command_parts), 'push',
                            'push {}'.format(arguments))
コード例 #23
0
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    upstream_option_index = -1
    try:
        upstream_option_index = command.script_parts.index('--set-upstream')
    except ValueError:
        pass
    try:
        upstream_option_index = command.script_parts.index('-u')
    except ValueError:
        pass
    if upstream_option_index is not -1:
        command.script_parts.pop(upstream_option_index)
        command.script_parts.pop(upstream_option_index)

    push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
    return replace_argument(" ".join(command.script_parts), 'push',
                            push_upstream)
コード例 #24
0
ファイル: git_push.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    # If --set-upstream or -u are passed, remove it and its argument. This is
    # because the remaining arguments are concatenated onto the command suggested
    # by git, which includes --set-upstream and its argument
    command_parts = command.script_parts[:]
    upstream_option_index = _get_upstream_option_index(command_parts)

    if upstream_option_index is not None:
        command_parts.pop(upstream_option_index)

        # In case of `git push -u` we don't have next argument:
        if len(command_parts) > upstream_option_index:
            command_parts.pop(upstream_option_index)
    else:
        # the only non-qualified permitted options are the repository and refspec; git's
        # suggestion include them, so they won't be lost, but would be duplicated otherwise.
        push_idx = command_parts.index('push') + 1
        while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
            command_parts.pop(len(command_parts) - 1)

    arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
    return replace_argument(" ".join(command_parts), 'push',
                            'push {}'.format(arguments))
コード例 #25
0
ファイル: git_add_force.py プロジェクト: mengdaya/fuckshell
def get_new_command(command):
    return replace_argument(command.script, 'add', 'add --force')
コード例 #26
0
def get_new_command(command):
    broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.stderr)[0]
    new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.stderr)
    if not new_cmd:
        new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.stderr)
    return replace_argument(command.script, broken_cmd, new_cmd[0].strip())
コード例 #27
0
def get_new_command(command):
    to = command.stderr.split('`')[1]
    return replace_argument(command.script, to[1:], to)
コード例 #28
0
def get_new_command(command):
    broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"',
                            command.output)[0]
    new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0]

    return replace_argument(command.script, broken_cmd, new_cmd)
コード例 #29
0
def get_new_command(command):
    return replace_argument(command.script, 'diff', 'diff --no-index')
コード例 #30
0
def get_new_command(command, settings):
    return replace_argument(command.script, '-d', '-D')
コード例 #31
0
ファイル: cargo_no_command.py プロジェクト: SanketDG/thefuck
def get_new_command(command, settings):
    broken = command.script.split()[1]
    fix = re.findall(r'Did you mean `([^`]*)`', command.stderr)[0]

    return replace_argument(command.script, broken, fix)
コード例 #32
0
ファイル: git_diff_no_index.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    return replace_argument(command.script, 'diff', 'diff --no-index')
コード例 #33
0
ファイル: php_s.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    return replace_argument(command.script, "-s", "-S")
コード例 #34
0
def get_new_command(command):
    broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
                            command.stderr)[0]
    new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0]

    return replace_argument(command.script, broken_cmd, new_cmd)
コード例 #35
0
def get_new_command(command):
    return replace_argument(command.script, 'diff', 'diff --staged')
コード例 #36
0
ファイル: git_push_pull.py プロジェクト: Aftermath/thefuck
def get_new_command(command, settings):
    return shells.and_(replace_argument(command.script, "push", "pull"), command.script)
コード例 #37
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.output)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
コード例 #38
0
ファイル: brew_install.py プロジェクト: MJerty/thefuck
def get_new_command(command):
    not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)',
                                   command.stderr)[0]
    exist_formula = _get_similar_formula(not_exist_formula)

    return replace_argument(command.script, not_exist_formula, exist_formula)
コード例 #39
0
ファイル: git_push_pull.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    return shell.and_(replace_argument(command.script, 'push', 'pull'),
                      command.script)
コード例 #40
0
def get_new_command(command, settings):
    return replace_argument(command.script, 'pull', 'clone')
コード例 #41
0
def test_replace_argument(args, result):
    assert replace_argument(*args) == result
コード例 #42
0
ファイル: git_pull_clone.py プロジェクト: Aftermath/thefuck
def get_new_command(command, settings):
    return replace_argument(command.script, 'pull', 'clone')
コード例 #43
0
ファイル: test_utils.py プロジェクト: liu4480/thefuck
def test_replace_argument(args, result):
    assert replace_argument(*args) == result
コード例 #44
0
def get_new_command(command, settings):
    wrong_command = re.findall(
        r"docker: '(\w+)' is not a docker command.", command.stderr)[0]
    fixed_command = get_closest(wrong_command, get_docker_commands())
    return replace_argument(command.script, wrong_command, fixed_command)
コード例 #45
0
ファイル: git_diff_staged.py プロジェクト: subajat1/thefuck
def get_new_command(command, settings):
    return replace_argument(command.script, 'diff', 'diff --staged')
コード例 #46
0
def get_new_command(command):
    return replace_argument(command.script, 'set-url', 'add')
コード例 #47
0
ファイル: tsuru_not_command.py プロジェクト: rayleyva/thefuck
def get_new_command(command, settings):
    broken_cmd = re.findall(r'tsuru: "([^"]*)" is not a tsuru command',
                            command.stderr)[0]
    new_cmd = get_closest(broken_cmd,
                          get_all_matched_commands(command.stderr))
    return replace_argument(command.script, broken_cmd, new_cmd)
コード例 #48
0
def get_new_command(command):
    command_name = _get_command_name(command)
    return replace_argument(command.script, command_name,
                            u'env "PATH=$PATH" {}'.format(command_name))
コード例 #49
0
ファイル: git_br_delete.py プロジェクト: ipwnponies/dotfiles
def get_new_command(command):
    return replace_argument(command.script, '-d', '-D')
コード例 #50
0
def get_new_command(command):
    return shells.and_(replace_argument(command.script, 'push', 'pull'),
                       command.script)
コード例 #51
0
def get_new_command(command):
    closest_subcommand = get_closest(command.script_parts[1], get_golang_commands())
    return replace_argument(command.script, command.script_parts[1],
                            closest_subcommand)
コード例 #52
0
ファイル: git_push_force.py プロジェクト: Clpsplug/thefuck
def get_new_command(command):
    return replace_argument(command.script, 'push', 'push --force-with-lease')
コード例 #53
0
ファイル: az_cli.py プロジェクト: yungdenzel/thefuck
def get_new_command(command):
    mistake = re.search(INVALID_CHOICE, command.output).group(1)
    options = re.findall(OPTIONS, command.output, flags=re.MULTILINE)
    return [replace_argument(command.script, mistake, o) for o in options]