This commit is contained in:
Yoav Tzelnick 2023-08-22 15:18:10 +02:00 committed by GitHub
commit 5a0b7f8693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View File

@ -1,20 +1,14 @@
import pytest
from thefuck.rules.rm_root import match, get_new_command
from thefuck.rules.rm_root import match
from thefuck.types import Command
def test_match():
assert match(Command('rm -rf /', 'add --no-preserve-root'))
assert match(Command('rm -rf /', ''))
@pytest.mark.parametrize('command', [
Command('ls', 'add --no-preserve-root'),
Command('rm --no-preserve-root /', 'add --no-preserve-root'),
Command('rm -rf /', '')])
Command('rm', '/usr/bin/python')])
def test_not_match(command):
assert not match(command)
def test_get_new_command():
assert (get_new_command(Command('rm -rf /', ''))
== 'rm -rf / --no-preserve-root')

View File

@ -1,3 +1,5 @@
import sys
from warnings import warn
from thefuck.specific.sudo import sudo_support
enabled_by_default = False
@ -6,11 +8,19 @@ enabled_by_default = False
@sudo_support
def match(command):
return (command.script_parts
and {'rm', '/'}.issubset(command.script_parts)
and '--no-preserve-root' not in command.script
and '--no-preserve-root' in command.output)
and {'rm', '/'}.issubset(command.script_parts))
@sudo_support
def get_new_command(command):
return u'{} --no-preserve-root'.format(command.script)
return '{} {} {}'.format(command.script_parts[0], '-rf', ' '.join(command.script_parts[1:]))
def side_effect(old_cmd, command):
warn("DANGER!!! THIS MAY DESTROY YOUR SYSTEM! ARE YOU SURE? (y/N): ")
try:
input = raw_input
except NameError:
pass
reply = input().strip().lower() # raw_input should be used in Python 2
if not reply or reply[0] != "y":
sys.exit(0)