#511: Add ln_s_order rule

This commit is contained in:
nvbn
2016-06-28 03:00:00 +03:00
parent 5866ea8433
commit f773b57bea
5 changed files with 70 additions and 2 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command):
return (command.stderr.endswith("hard link not allowed for directory") and
command.script.startswith("ln "))
command.script_parts[0] == 'ln')
@sudo_support
+26
View File
@@ -0,0 +1,26 @@
import os
from thefuck.specific.sudo import sudo_support
def _get_destination(script_parts):
"""When arguments order is wrong first argument will be destination."""
for part in script_parts:
if part not in {'ln', '-s', '--symbolic'} and os.path.exists(part):
return part
@sudo_support
def match(command):
return (command.script_parts[0] == 'ln'
and {'-s', '--symbolic'}.intersection(command.script_parts)
and 'File exists' in command.stderr
and _get_destination(command.script_parts))
@sudo_support
def get_new_command(command):
destination = _get_destination(command.script_parts)
parts = command.script_parts[:]
parts.remove(destination)
parts.append(destination)
return ' '.join(parts)