diff --git a/tests/rules/test_hostscli.py b/tests/rules/test_hostscli.py index 1736d43e..1c6cc5cf 100644 --- a/tests/rules/test_hostscli.py +++ b/tests/rules/test_hostscli.py @@ -1,20 +1,6 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- -# -# vim: fenc=utf-8 -# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 -# -# - -""" -File name: test_hostscli.py -Author: dhilipsiva -Date created: 2017-02-05 -""" - import pytest -from thefuck.rules.hostscli import no_command, need_sudo, no_website, \ - match, get_new_command +from thefuck.rules.hostscli import no_command, no_website, get_new_command, \ + match from tests.utils import Command @@ -24,14 +10,6 @@ Usage: hostscli [OPTIONS] COMMAND [ARGS]... %s "invalid". ''' % no_command -need_sudo = ''' -%s: - -"sudo" permissions are required to run this command. - -Please run the last command again with sudo -''' % need_sudo - no_website = ''' %s: @@ -54,9 +32,6 @@ def test_match(command): @pytest.mark.parametrize('command, result', [ (Command( 'hostscli invalid', stderr=no_command), ['hostscli --help']), - (Command( - 'hostscli block test', stderr=need_sudo), - ['sudo hostscli block test']), (Command( 'sudo hostscli block a_website_that_does_not_exist', stderr=no_website), diff --git a/thefuck/rules/hostscli.py b/thefuck/rules/hostscli.py index 7f3bd6fb..d62b6437 100644 --- a/thefuck/rules/hostscli.py +++ b/thefuck/rules/hostscli.py @@ -1,27 +1,14 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- -# -# vim: fenc=utf-8 -# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 -# -# +import re -""" -File name: hostscli.py -Author: dhilipsiva -Date created: 2017-02-05 -""" - -from thefuck.utils import for_app +from thefuck.utils import for_app, replace_command no_command = "Error: No such command" -need_sudo = "hostscli.errors.SudoRequiredError" no_website = "hostscli.errors.WebsiteImportError" @for_app("hostscli") def match(command): - errors = [no_command, need_sudo, no_website] + errors = [no_command, no_website] for error in errors: if error in command.stderr: return True @@ -31,7 +18,7 @@ def match(command): def get_new_command(command): if no_website in command.stderr: return ['hostscli websites'] - if need_sudo in command.stderr: - return ['sudo {}'.format(command.script)] - if no_command in command.stderr: - return ['hostscli --help'] + misspelled_command = re.findall( + r'Error: No such command "(.*)"', command.stderr)[0] + commands = ['block', 'unblock', 'websites', 'block_all', 'unblock_all'] + return replace_command(command, misspelled_command, commands) diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 91e5f4bb..0f85168a 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -20,7 +20,8 @@ patterns = ['permission denied', 'authentication is required', 'edspermissionerror', 'you don\'t have write permissions', - 'use `sudo`'] + 'use `sudo`', + 'SudoRequiredError'] def match(command):