mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#N/A: Add a new rule to create directory on cp or mv
This commit is contained in:
parent
444908ce1c
commit
88db57b4b1
@ -184,6 +184,7 @@ following rules are enabled by default:
|
||||
* `chmod_x` – add execution bit;
|
||||
* `choco_install` – append common suffixes for chocolatey packages;
|
||||
* `composer_not_command` – fixes composer command name;
|
||||
* `cp_create_destination` – creates a new directory when you attempt to `cp` or `mv` to a non existent one
|
||||
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
|
||||
* `cpp11` – adds missing `-std=c++11` to `g++` or `clang++`;
|
||||
* `dirty_untar` – fixes `tar x` command that untarred in the current directory;
|
||||
|
30
tests/rules/test_cp_create_destination.py
Normal file
30
tests/rules/test_cp_create_destination.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pytest
|
||||
from thefuck.rules.cp_create_destination import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output",
|
||||
[("cp", "cp: directory foo does not exist\n"), ("mv", "No such file or directory")],
|
||||
)
|
||||
def test_match(script, output):
|
||||
assert match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output", [("cp", ""), ("mv", ""), ("ls", "No such file or directory")]
|
||||
)
|
||||
def test_not_match(script, output):
|
||||
assert not match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output, new_command",
|
||||
[
|
||||
("cp foo bar/", "cp: directory foo does not exist\n", "mkdir -p bar/ && cp foo bar/"),
|
||||
("mv foo bar/", "No such file or directory", "mkdir -p bar/ && mv foo bar/"),
|
||||
("cp foo bar/baz/", "cp: directory foo does not exist\n", "mkdir -p bar/baz/ && cp foo bar/baz/"),
|
||||
],
|
||||
)
|
||||
def test_get_new_command(script, output, new_command):
|
||||
assert get_new_command(Command(script, output)) == new_command
|
15
thefuck/rules/cp_create_destination.py
Normal file
15
thefuck/rules/cp_create_destination.py
Normal file
@ -0,0 +1,15 @@
|
||||
from thefuck.shells import shell
|
||||
from thefuck.utils import for_app
|
||||
|
||||
|
||||
@for_app("cp", "mv")
|
||||
def match(command):
|
||||
return (
|
||||
"No such file or directory" in command.output
|
||||
or command.output.startswith("cp: directory")
|
||||
and command.output.rstrip().endswith("does not exist")
|
||||
)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return shell.and_(u"mkdir -p {}".format(command.script_parts[-1]), command.script)
|
Loading…
x
Reference in New Issue
Block a user