Merge 2d0b907356 into 62e0767c50
This commit is contained in:
commit
5a0b7f8693
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue