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:
dhilipsiva
2017-02-09 08:46:54 +05:30
parent fb07cdfb4a
commit 7f9025c7ad
3 changed files with 11 additions and 48 deletions
+7 -20
View File
@@ -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)
+2 -1
View File
@@ -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):