mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 02:01:13 +00:00
Make Changes suggested by @nvbn
* remove comments/doctrings at the top of files; * move sudo-related stuff to sudo rule; * for no_command case try to find most similar command, like, for example, in react_native_command_unrecognized rule.
This commit is contained in:
parent
fb07cdfb4a
commit
7f9025c7ad
@ -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 <dhilipsiva@gmail.com>
|
||||
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),
|
||||
|
@ -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 <dhilipsiva@gmail.com>
|
||||
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)
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user