diff --git a/tests/rules/test_cp_omitting_directory.py b/tests/rules/test_cp_omitting_directory.py new file mode 100644 index 00000000..0f4a3bf8 --- /dev/null +++ b/tests/rules/test_cp_omitting_directory.py @@ -0,0 +1,14 @@ +from mock import Mock +from thefuck.rules.cp_omitting_directory import match, get_new_command + + +def test_match(): + assert match(Mock(script='cp dir', stderr="cp: omitting directory 'dir'"), + None) + assert not match(Mock(script='some dir', + stderr="cp: omitting directory 'dir'"), None) + assert not match(Mock(script='cp dir', stderr=""), None) + + +def test_get_new_command(): + assert get_new_command(Mock(script='cp dir'), None) == 'cp -a dir' diff --git a/thefuck/rules/cp_omitting_directory.py b/thefuck/rules/cp_omitting_directory.py new file mode 100644 index 00000000..14e84c9c --- /dev/null +++ b/thefuck/rules/cp_omitting_directory.py @@ -0,0 +1,10 @@ +import re + + +def match(command, settings): + return command.script.startswith('cp ') \ + and 'cp: omitting directory' in command.stderr.lower() + + +def get_new_command(command, settings): + return re.sub(r'^cp', 'cp -a', command.script)