mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
commit
abbbd1f8eb
@ -218,7 +218,11 @@ match(command: Command, settings: Settings) -> bool
|
|||||||
get_new_command(command: Command, settings: Settings) -> str | list[str]
|
get_new_command(command: Command, settings: Settings) -> str | list[str]
|
||||||
```
|
```
|
||||||
|
|
||||||
Also the rule can contain an optional function `side_effect(command: Command, settings: Settings) -> None`
|
Also the rule can contain an optional function
|
||||||
|
|
||||||
|
```python
|
||||||
|
side_effect(old_command: Command, fixed_command: str, settings: Settings) -> None
|
||||||
|
```
|
||||||
and optional `enabled_by_default`, `requires_output` and `priority` variables.
|
and optional `enabled_by_default`, `requires_output` and `priority` variables.
|
||||||
|
|
||||||
`Command` has three attributes: `script`, `stdout` and `stderr`.
|
`Command` has three attributes: `script`, `stdout` and `stderr`.
|
||||||
|
@ -52,7 +52,7 @@ def test_match(tar_error, filename, script, fixed):
|
|||||||
@parametrize_script
|
@parametrize_script
|
||||||
def test_side_effect(tar_error, filename, script, fixed):
|
def test_side_effect(tar_error, filename, script, fixed):
|
||||||
tar_error(filename)
|
tar_error(filename)
|
||||||
side_effect(Command(script=script.format(filename)), None)
|
side_effect(Command(script=script.format(filename)), None, None)
|
||||||
assert(os.listdir('.') == [filename])
|
assert(os.listdir('.') == [filename])
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ def test_match(zip_error, script):
|
|||||||
'unzip foo',
|
'unzip foo',
|
||||||
'unzip foo.zip'])
|
'unzip foo.zip'])
|
||||||
def test_side_effect(zip_error, script):
|
def test_side_effect(zip_error, script):
|
||||||
side_effect(Command(script=script), None)
|
side_effect(Command(script=script), None, None)
|
||||||
assert(os.listdir('.') == ['foo.zip'])
|
assert(os.listdir('.') == ['foo.zip'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ def test_match(ssh_error):
|
|||||||
def test_side_effect(ssh_error):
|
def test_side_effect(ssh_error):
|
||||||
errormsg, path, reset, known_hosts = ssh_error
|
errormsg, path, reset, known_hosts = ssh_error
|
||||||
command = Command('ssh user@host', stderr=errormsg)
|
command = Command('ssh user@host', stderr=errormsg)
|
||||||
side_effect(command, None)
|
side_effect(command, None, None)
|
||||||
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
||||||
assert known_hosts(path) == expected
|
assert known_hosts(path) == expected
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ def get_command(settings, args):
|
|||||||
return types.Command(script, None, None)
|
return types.Command(script, None, None)
|
||||||
|
|
||||||
|
|
||||||
def run_command(command, settings):
|
def run_command(old_cmd, command, settings):
|
||||||
"""Runs command from rule for passed command."""
|
"""Runs command from rule for passed command."""
|
||||||
if command.side_effect:
|
if command.side_effect:
|
||||||
command.side_effect(command, settings)
|
command.side_effect(old_cmd, command.script, settings)
|
||||||
shells.put_to_history(command.script)
|
shells.put_to_history(command.script)
|
||||||
print(command.script)
|
print(command.script)
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ def fix_command():
|
|||||||
corrected_commands = get_corrected_commands(command, user_dir, settings)
|
corrected_commands = get_corrected_commands(command, user_dir, settings)
|
||||||
selected_command = select_command(corrected_commands, settings)
|
selected_command = select_command(corrected_commands, settings)
|
||||||
if selected_command:
|
if selected_command:
|
||||||
run_command(selected_command, settings)
|
run_command(command, selected_command, settings)
|
||||||
|
|
||||||
|
|
||||||
def print_alias(entry_point=True):
|
def print_alias(entry_point=True):
|
||||||
|
@ -35,7 +35,7 @@ def get_new_command(command, settings):
|
|||||||
.format(dir=_tar_file(command.script)[1], cmd=command.script)
|
.format(dir=_tar_file(command.script)[1], cmd=command.script)
|
||||||
|
|
||||||
|
|
||||||
def side_effect(command, settings):
|
def side_effect(old_cmd, command, settings):
|
||||||
with tarfile.TarFile(_tar_file(command.script)[0]) as archive:
|
with tarfile.TarFile(_tar_file(old_cmd.script)[0]) as archive:
|
||||||
for file in archive.getnames():
|
for file in archive.getnames():
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
@ -30,8 +30,8 @@ def get_new_command(command, settings):
|
|||||||
return '{} -d {}'.format(command.script, _zip_file(command)[:-4])
|
return '{} -d {}'.format(command.script, _zip_file(command)[:-4])
|
||||||
|
|
||||||
|
|
||||||
def side_effect(command, settings):
|
def side_effect(old_cmd, command, settings):
|
||||||
with zipfile.ZipFile(_zip_file(command), 'r') as archive:
|
with zipfile.ZipFile(_zip_file(old_cmd), 'r') as archive:
|
||||||
for file in archive.namelist():
|
for file in archive.namelist():
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ def get_new_command(command, settings):
|
|||||||
return command.script
|
return command.script
|
||||||
|
|
||||||
|
|
||||||
def side_effect(command, settings):
|
def side_effect(old_cmd, command, settings):
|
||||||
offending = offending_pattern.findall(command.stderr)
|
offending = offending_pattern.findall(old_cmd.stderr)
|
||||||
for filepath, lineno in offending:
|
for filepath, lineno in offending:
|
||||||
with open(filepath, 'r') as fh:
|
with open(filepath, 'r') as fh:
|
||||||
lines = fh.readlines()
|
lines = fh.readlines()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user