-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#N/A: Add a new rule to create directory on cp or mv
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |