mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 13:41:21 +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
|
import pytest
|
||||||
from thefuck.rules.hostscli import no_command, need_sudo, no_website, \
|
from thefuck.rules.hostscli import no_command, no_website, get_new_command, \
|
||||||
match, get_new_command
|
match
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
@ -24,14 +10,6 @@ Usage: hostscli [OPTIONS] COMMAND [ARGS]...
|
|||||||
%s "invalid".
|
%s "invalid".
|
||||||
''' % no_command
|
''' % 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 = '''
|
no_website = '''
|
||||||
%s:
|
%s:
|
||||||
@ -54,9 +32,6 @@ def test_match(command):
|
|||||||
@pytest.mark.parametrize('command, result', [
|
@pytest.mark.parametrize('command, result', [
|
||||||
(Command(
|
(Command(
|
||||||
'hostscli invalid', stderr=no_command), ['hostscli --help']),
|
'hostscli invalid', stderr=no_command), ['hostscli --help']),
|
||||||
(Command(
|
|
||||||
'hostscli block test', stderr=need_sudo),
|
|
||||||
['sudo hostscli block test']),
|
|
||||||
(Command(
|
(Command(
|
||||||
'sudo hostscli block a_website_that_does_not_exist',
|
'sudo hostscli block a_website_that_does_not_exist',
|
||||||
stderr=no_website),
|
stderr=no_website),
|
||||||
|
@ -1,27 +1,14 @@
|
|||||||
#! /usr/bin/env python
|
import re
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# vim: fenc=utf-8
|
|
||||||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
from thefuck.utils import for_app, replace_command
|
||||||
File name: hostscli.py
|
|
||||||
Author: dhilipsiva <dhilipsiva@gmail.com>
|
|
||||||
Date created: 2017-02-05
|
|
||||||
"""
|
|
||||||
|
|
||||||
from thefuck.utils import for_app
|
|
||||||
|
|
||||||
no_command = "Error: No such command"
|
no_command = "Error: No such command"
|
||||||
need_sudo = "hostscli.errors.SudoRequiredError"
|
|
||||||
no_website = "hostscli.errors.WebsiteImportError"
|
no_website = "hostscli.errors.WebsiteImportError"
|
||||||
|
|
||||||
|
|
||||||
@for_app("hostscli")
|
@for_app("hostscli")
|
||||||
def match(command):
|
def match(command):
|
||||||
errors = [no_command, need_sudo, no_website]
|
errors = [no_command, no_website]
|
||||||
for error in errors:
|
for error in errors:
|
||||||
if error in command.stderr:
|
if error in command.stderr:
|
||||||
return True
|
return True
|
||||||
@ -31,7 +18,7 @@ def match(command):
|
|||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
if no_website in command.stderr:
|
if no_website in command.stderr:
|
||||||
return ['hostscli websites']
|
return ['hostscli websites']
|
||||||
if need_sudo in command.stderr:
|
misspelled_command = re.findall(
|
||||||
return ['sudo {}'.format(command.script)]
|
r'Error: No such command "(.*)"', command.stderr)[0]
|
||||||
if no_command in command.stderr:
|
commands = ['block', 'unblock', 'websites', 'block_all', 'unblock_all']
|
||||||
return ['hostscli --help']
|
return replace_command(command, misspelled_command, commands)
|
||||||
|
@ -20,7 +20,8 @@ patterns = ['permission denied',
|
|||||||
'authentication is required',
|
'authentication is required',
|
||||||
'edspermissionerror',
|
'edspermissionerror',
|
||||||
'you don\'t have write permissions',
|
'you don\'t have write permissions',
|
||||||
'use `sudo`']
|
'use `sudo`',
|
||||||
|
'SudoRequiredError']
|
||||||
|
|
||||||
|
|
||||||
def match(command):
|
def match(command):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user