1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-04-20 17:50:45 +01:00

Merge pull request #264 from mcarton/cleanup

Cleanup
This commit is contained in:
Vladimir Iakovlev 2015-06-26 17:30:14 +03:00
commit cb33c912e5
16 changed files with 102 additions and 96 deletions

View File

@ -154,12 +154,10 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `composer_not_command` – fixes composer command name;
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
* `cpp11` – add missing `-std=c++11` to `g++` or `clang++`;
* `dry` – fix repetitions like "git git push";
* `django_south_ghost` – adds `--delete-ghost-migrations` to failed because ghosts django south migration;
* `django_south_merge` – adds `--merge` to inconsistent django south migration;
* `dry` – fix repetitions like "git git push";
* `fix_alt_space` – replaces Alt+Space with Space character;
* `javac` – appends missing `.java` when compiling Java files;
* `java` – removes `.java` extension when running Java programs;
* `git_add` – fix *"Did you forget to 'git add'?"*;
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
* `git_checkout` – creates the branch before checking-out;
@ -171,6 +169,8 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `go_run` – appends `.go` extension when compiling/running Go programs
* `grep_recursive` – adds `-r` when you trying to grep directory;
* `has_exists_script` – prepends `./` when script/binary exists;
* `java` – removes `.java` extension when running Java programs;
* `javac` – appends missing `.java` when compiling Java files;
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
* `ls_lah` – adds -lah to ls;
* `man` – change manual section;
@ -181,7 +181,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `open` – prepends `http` to address passed to `open`;
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
* `python_compile` – appends missing `.py` when compiling and running Python files;
* `python_execute` – appends missing `.py` when executing Python files;
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'
* `rm_dir` – adds `-rf` when you trying to remove directory;
* `sl_ls` – changes `sl` to `ls`;
@ -212,7 +212,7 @@ in `~/.thefuck/rules`. Rule should contain two functions:
and `get_new_command(command: Command, settings: Settings) -> str`.
Also the rule can contain optional function
`side_effect(command: Command, settings: Settings) -> None` and
optional boolean `enabled_by_default`
optional boolean `enabled_by_default`.
`Command` has three attributes: `script`, `stdout` and `stderr`.

View File

@ -1,17 +0,0 @@
import pytest
from thefuck.rules.python_compile import match, get_new_command
from tests.utils import Command
@pytest.mark.parametrize('command', [
Command(script='python foo'),
Command(script='python bar')])
def test_match(command):
assert match(command, None)
@pytest.mark.parametrize('command, new_command', [
(Command('python foo'), 'python foo.py'),
(Command('python bar'), 'python bar.py')])
def test_get_new_command(command, new_command):
assert get_new_command(command, None) == new_command

View File

@ -0,0 +1,17 @@
import pytest
from thefuck.rules.python_execute import match, get_new_command
from tests.utils import Command
@pytest.mark.parametrize('command', [
Command(script='python foo'),
Command(script='python bar')])
def test_match(command):
assert match(command, None)
@pytest.mark.parametrize('command, new_command', [
(Command('python foo'), 'python foo.py'),
(Command('python bar'), 'python bar.py')])
def test_get_new_command(command, new_command):
assert get_new_command(command, None) == new_command

View File

@ -1,3 +1,6 @@
from thefuck import shells
def match(command, settings):
return ('git' in command.script
and 'pull' in command.script
@ -9,4 +12,4 @@ def get_new_command(command, settings):
branch = line.split(' ')[-1]
set_upstream = line.replace('<remote>', 'origin')\
.replace('<branch>', branch)
return u'{} && {}'.format(set_upstream, command.script)
return shells.and_(set_upstream, command.script)

View File

@ -3,11 +3,12 @@
# Example:
# > java foo.java
# Error: Could not find or load main class foo.java
#
def match(command, settings):
return (command.script.startswith ('java ')
and command.script.endswith ('.java'))
return (command.script.startswith('java ')
and command.script.endswith('.java'))
def get_new_command(command, settings):
return command.script[:-5]

View File

@ -4,12 +4,12 @@
# > javac foo
# error: Class names, 'foo', are only accepted if annotation
# processing is explicitly requested
#
#
def match(command, settings):
return (command.script.startswith ('javac ')
return (command.script.startswith('javac ')
and not command.script.endswith('.java'))
def get_new_command(command, settings):
return command.script + '.java'

View File

@ -1,15 +0,0 @@
# Appends .py when compiling python files
#
# Example:
# > python foo
# error: python: can't open file 'foo': [Errno 2] No such file or directory
#
#
def match(command, settings):
return (command.script.startswith ('python ')
and not command.script.endswith('.py'))
def get_new_command(command, settings):
return command.script + '.py'

View File

@ -0,0 +1,14 @@
# Appends .py when executing python files
#
# Example:
# > python foo
# error: python: can't open file 'foo': [Errno 2] No such file or directory
def match(command, settings):
return (command.script.startswith('python ')
and not command.script.endswith('.py'))
def get_new_command(command, settings):
return command.script + '.py'

View File

@ -7,14 +7,12 @@ patterns = ['permission denied',
'root privilege',
'This command has to be run under the root user.',
'This operation requires root.',
'You need to be root to perform this command.',
'requested operation requires superuser privilege',
'must be run as root',
'must be superuser',
'must be root',
'need to be root',
'need root',
'you must be root to run this program.',
'only root can do that']

View File

@ -1,16 +1,21 @@
"""
The confusion in systemctl's param order is massive
The confusion in systemctl's param order is massive.
"""
from thefuck.utils import sudo_support
@sudo_support
def match(command, settings):
#Catches 'Unknown operation 'service'.' when executing systemctl with misordered arguments
# Catches 'Unknown operation 'service'.' when executing systemctl with
# misordered arguments
cmd = command.script.split()
return ('systemctl' in command.script) and ('Unknown operation \'' in command.stderr) and (len(cmd) - cmd.index('systemctl') == 3);
return ('systemctl' in command.script and
'Unknown operation \'' in command.stderr and
len(cmd) - cmd.index('systemctl') == 3)
@sudo_support
def get_new_command(command, settings):
cmd = command.script.split()
cmd[len(cmd)-1], cmd[len(cmd)-2] = cmd[len(cmd)-2], cmd[len(cmd)-1]
cmd[-1], cmd[-2] = cmd[-2], cmd[-1]
return ' '.join(cmd)