1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-11-01 15:42:06 +00:00

Compare commits

...

25 Commits
2.4 ... 2.5

Author SHA1 Message Date
nvbn
af40ad84d8 Bump to 2.5 2015-07-27 22:23:26 +03:00
nvbn
63e62fcba3 #311 Use setuptools-markdown 2015-07-27 22:23:20 +03:00
nvbn
368be788d7 Fix tests in python 2 2015-07-27 17:51:33 +03:00
nvbn
cd1468489f Fix history tests in travis-ci? 2015-07-27 17:47:02 +03:00
nvbn
fbce86b92a Merge branch 'mcarton-unzip-clean' 2015-07-27 17:40:04 +03:00
nvbn
3f6652df66 #313 Add new command options to readme 2015-07-27 17:39:52 +03:00
nvbn
cf82af8978 #313 Remove types.Script, use Command with None as stdout and stderr 2015-07-27 17:39:41 +03:00
nvbn
20f51f5ffe Merge branch 'unzip-clean' of https://github.com/mcarton/thefuck into mcarton-unzip-clean 2015-07-27 17:29:09 +03:00
nvbn
8f6d8b1dd1 Add tests for history changes fro bash and zsh 2015-07-27 17:28:09 +03:00
Vladimir Iakovlev
c0002fe6e0 Merge pull request #317 from SanketDG/setup_fix
fix setup.py version checking
2015-07-27 01:05:25 +03:00
Vladimir Iakovlev
6609b8d06a #316 Remove .py from tsuru_login rule name 2015-07-26 22:09:55 +03:00
Vladimir Iakovlev
5b5df9361d Merge pull request #316 from scorphus/tsuru-login
Add `tsuru_login` rule
2015-07-26 22:08:51 +03:00
Vladimir Iakovlev
fa234fde70 Merge pull request #315 from scorphus/fix-tests
Fix git_push_pull and not_match tests
2015-07-26 22:08:09 +03:00
SanketDG
867aec83c3 fix setup.py version checking 2015-07-26 23:47:56 +05:30
Pablo Santiago Blum de Aguiar
2117659c40 Add tsuru_login rule 2015-07-25 23:33:38 -03:00
Pablo Santiago Blum de Aguiar
4985f75d74 Allow generic_shell to act while testing git_push_pull
Fix failing tests on shells that do not use && operator
2015-07-25 23:26:52 -03:00
Pablo Santiago Blum de Aguiar
959d20df78 Add test_not_match to no_such_file tests 2015-07-25 23:26:47 -03:00
mcarton
8529461742 Update README 2015-07-25 23:14:10 +02:00
mcarton
3173ef10c6 Change the message when expecting side effect
The previous behavior is really surprising:
```
    some_command* [enter/ctrl+c]
   |<~~~~~~~~~~~>|<~~~~~~~~~~~~>|
   |  bold text  | normal weight|
```
as if the '*' is part of the command to be executed.
The new behavior is:
```
    some_command (+side effect) [enter/ctrl+c]
   |<~~~~~~~~~~>|<~~~~~~~~~~~~~~~~~~~~~~~~~~~>|
   |  bold text |        normal weight        |
```
2015-07-25 23:10:21 +02:00
mcarton
1c5fef3a34 Add tests for the dirty_untar rule 2015-07-25 23:06:20 +02:00
mcarton
386e6bf0c3 Add the dirty_tar rule 2015-07-25 23:06:09 +02:00
mcarton
1146ab654c Add tests for the dirty_unzip rule 2015-07-25 23:06:00 +02:00
mcarton
4e7eceaa3a Add a dirty_unzip rule 2015-07-25 23:05:06 +02:00
mcarton
71bb1994c3 Allow rules to correct commands that time out 2015-07-25 23:04:08 +02:00
nvbn
bfa3c905a3 Improve assertions in func tests 2015-07-25 21:02:04 +03:00
21 changed files with 355 additions and 51 deletions

View File

@@ -139,6 +139,8 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `composer_not_command` &ndash; fixes composer command name;
* `cp_omitting_directory` &ndash; adds `-a` when you `cp` directory;
* `cpp11` &ndash; adds missing `-std=c++11` to `g++` or `clang++`;
* `dirty_untar` &ndash; fixes `tar x` command that untarred in the current directory;
* `dirty_unzip` &ndash; fixes `unzip` command that unzipped in the current directory;
* `django_south_ghost` &ndash; adds `--delete-ghost-migrations` to failed because ghosts django south migration;
* `django_south_merge` &ndash; adds `--merge` to inconsistent django south migration;
* `docker_not_command` &ndash; fixes wrong docker commands like `docker tags`;
@@ -185,6 +187,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `switch_layout` &ndash; switches command from your local layout to en;
* `systemctl` &ndash; correctly orders parameters of confusing `systemctl`;
* `test.py` &ndash; runs `py.test` instead of `test.py`;
* `tsuru_login` &ndash; runs `tsuru login` if not authenticated or session expired;
* `tmux` &ndash; fixes `tmux` commands;
* `whois` &ndash; fixes `whois` command.
@@ -211,8 +214,8 @@ get_new_command(command: Command, settings: Settings) -> str
```
Also the rule can contain an optional function
`side_effect(command: Command, settings: Settings) -> None` and an
optional boolean `enabled_by_default`.
`side_effect(command: Command, settings: Settings) -> None` and
optional `enabled_by_default`, `requires_output` and `priority` variables.
`Command` has three attributes: `script`, `stdout` and `stderr`.
@@ -236,6 +239,8 @@ def side_effect(command, settings):
subprocess.call('chmod 777 .', shell=True)
priority = 1000 # Lower first, default is 1000
requires_output = True
```
[More examples of rules](https://github.com/nvbn/thefuck/tree/master/thefuck/rules),
@@ -304,5 +309,12 @@ Run unit and functional tests (requires docker):
FUNCTIONAL=true py.test
```
For sending package to pypi:
```bash
sudo apt-get install pandoc
./release.py
```
## License MIT
Project License can be found [here](LICENSE.md).

View File

@@ -1,4 +1,2 @@
[bdist_wheel]
universal = 1
[metadata]
description-file = README.md

View File

@@ -2,16 +2,17 @@
from setuptools import setup, find_packages
import sys
if sys.version_info < (2, 7):
version = sys.version_info[:2]
if version < (2, 7):
print('thefuck requires Python version 2.7 or later' +
' ({}.{} detected).'.format(*sys.version_info[:2]))
' ({}.{} detected).'.format(*version))
sys.exit(-1)
elif (3, 0) < sys.version_info < (3, 3):
elif (3, 0) < version < (3, 3):
print('thefuck requires Python version 3.3 or later' +
' ({}.{} detected).'.format(*sys.version_info[:2]))
' ({}.{} detected).'.format(*version))
sys.exit(-1)
VERSION = '2.4'
VERSION = '2.5'
install_requires = ['psutil', 'colorama', 'six']
extras_require = {':python_version<"3.4"': ['pathlib']}
@@ -25,6 +26,8 @@ setup(name='thefuck',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples',
'tests', 'release']),
setup_requires=['setuptools-markdown'],
long_description_markdown_filename='README.md',
include_package_data=True,
zip_safe=False,
install_requires=install_requires,

View File

@@ -1,3 +1,6 @@
from pexpect import TIMEOUT
def with_confirmation(proc):
"""Ensures that command can be fixed when confirmation enabled."""
proc.sendline(u'mkdir -p ~/.thefuck')
@@ -6,12 +9,24 @@ def with_confirmation(proc):
proc.sendline(u'ehco test')
proc.sendline(u'fuck')
proc.expect(u'echo test')
proc.expect(u'enter')
proc.expect_exact(u'ctrl+c')
assert proc.expect([TIMEOUT, u'echo test'])
assert proc.expect([TIMEOUT, u'enter'])
assert proc.expect_exact([TIMEOUT, u'ctrl+c'])
proc.send('\n')
proc.expect(u'test')
assert proc.expect([TIMEOUT, u'test'])
def history_changed(proc):
"""Ensures that history changed."""
proc.send('\033[A')
assert proc.expect([TIMEOUT, u'echo test'])
def history_not_changed(proc):
"""Ensures that history not changed."""
proc.send('\033[A')
assert proc.expect([TIMEOUT, u'fuck'])
def refuse_with_confirmation(proc):
@@ -22,12 +37,12 @@ def refuse_with_confirmation(proc):
proc.sendline(u'ehco test')
proc.sendline(u'fuck')
proc.expect(u'echo test')
proc.expect(u'enter')
proc.expect_exact(u'ctrl+c')
assert proc.expect([TIMEOUT, u'echo test'])
assert proc.expect([TIMEOUT, u'enter'])
assert proc.expect_exact([TIMEOUT, u'ctrl+c'])
proc.send('\003')
proc.expect(u'Aborted')
assert proc.expect([TIMEOUT, u'Aborted'])
def without_confirmation(proc):
@@ -38,5 +53,5 @@ def without_confirmation(proc):
proc.sendline(u'ehco test')
proc.sendline(u'fuck')
proc.expect(u'echo test')
proc.expect(u'test')
assert proc.expect([TIMEOUT, u'echo test'])
assert proc.expect([TIMEOUT, u'test'])

View File

@@ -1,6 +1,6 @@
import pytest
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation
refuse_with_confirmation, history_changed, history_not_changed
from tests.functional.utils import spawn, functional, images
containers = images(('ubuntu-python3-bash', u'''
@@ -22,21 +22,30 @@ RUN pip2 install -U pip setuptools
@pytest.mark.parametrize('tag, dockerfile', containers)
def test_with_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'bash') as proc:
proc.sendline(u"export PS1='$ '")
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'touch $HISTFILE')
with_confirmation(proc)
history_changed(proc)
@functional
@pytest.mark.parametrize('tag, dockerfile', containers)
def test_refuse_with_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'bash') as proc:
proc.sendline(u"export PS1='$ '")
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'touch $HISTFILE')
refuse_with_confirmation(proc)
history_not_changed(proc)
@functional
@pytest.mark.parametrize('tag, dockerfile', containers)
def test_without_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'bash') as proc:
proc.sendline(u"export PS1='$ '")
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'touch $HISTFILE')
without_confirmation(proc)
history_changed(proc)

View File

@@ -49,3 +49,5 @@ def test_without_confirmation(tag, dockerfile):
proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish')
proc.sendline(u'fish')
without_confirmation(proc)
# TODO: ensure that history changes.

View File

@@ -43,3 +43,5 @@ def test_without_confirmation(tag, dockerfile):
proc.sendline(u'tcsh')
proc.sendline(u'eval `thefuck-alias`')
without_confirmation(proc)
# TODO: ensure that history changes.

View File

@@ -1,7 +1,7 @@
import pytest
from tests.functional.utils import spawn, functional, images
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation
refuse_with_confirmation, history_changed, history_not_changed
containers = images(('ubuntu-python3-zsh', u'''
FROM ubuntu:latest
@@ -23,7 +23,10 @@ RUN pip2 install -U pip setuptools
def test_with_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'zsh') as proc:
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'export HISTFILE=~/.zsh_history')
proc.sendline(u'touch $HISTFILE')
with_confirmation(proc)
history_changed(proc)
@functional
@@ -31,7 +34,10 @@ def test_with_confirmation(tag, dockerfile):
def test_refuse_with_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'zsh') as proc:
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'export HISTFILE=~/.zsh_history')
proc.sendline(u'touch $HISTFILE')
refuse_with_confirmation(proc)
history_not_changed(proc)
@functional
@@ -39,4 +45,7 @@ def test_refuse_with_confirmation(tag, dockerfile):
def test_without_confirmation(tag, dockerfile):
with spawn(tag, dockerfile, u'zsh') as proc:
proc.sendline(u'eval $(thefuck-alias)')
proc.sendline(u'export HISTFILE=~/.zsh_history')
proc.sendline(u'touch $HISTFILE')
without_confirmation(proc)
history_changed(proc)

View File

@@ -0,0 +1,62 @@
import os
import pytest
import tarfile
from thefuck.rules.dirty_untar import match, get_new_command, side_effect
from tests.utils import Command
@pytest.fixture
def tar_error(tmpdir):
def fixture(filename):
path = os.path.join(str(tmpdir), filename)
def reset(path):
with tarfile.TarFile(path, 'w') as archive:
for file in ('a', 'b', 'c'):
with open(file, 'w') as f:
f.write('*')
archive.add(file)
os.remove(file)
with tarfile.TarFile(path, 'r') as archive:
archive.extractall()
os.chdir(str(tmpdir))
reset(path)
assert(set(os.listdir('.')) == {filename, 'a', 'b', 'c'})
return fixture
parametrize_filename = pytest.mark.parametrize('filename', [
'foo.tar',
'foo.tar.gz',
'foo.tgz'])
parametrize_script = pytest.mark.parametrize('script, fixed', [
('tar xvf {}', 'mkdir -p foo && tar xvf {} -C foo'),
('tar -xvf {}', 'mkdir -p foo && tar -xvf {} -C foo'),
('tar --extract -f {}', 'mkdir -p foo && tar --extract -f {} -C foo')])
@parametrize_filename
@parametrize_script
def test_match(tar_error, filename, script, fixed):
tar_error(filename)
assert match(Command(script=script.format(filename)), None)
@parametrize_filename
@parametrize_script
def test_side_effect(tar_error, filename, script, fixed):
tar_error(filename)
side_effect(Command(script=script.format(filename)), None)
assert(os.listdir('.') == [filename])
@parametrize_filename
@parametrize_script
def test_get_new_command(tar_error, filename, script, fixed):
tar_error(filename)
assert get_new_command(Command(script=script.format(filename)), None) == fixed.format(filename)

View File

@@ -0,0 +1,45 @@
import os
import pytest
import zipfile
from thefuck.rules.dirty_unzip import match, get_new_command, side_effect
from tests.utils import Command
@pytest.fixture
def zip_error(tmpdir):
path = os.path.join(str(tmpdir), 'foo.zip')
def reset(path):
with zipfile.ZipFile(path, 'w') as archive:
archive.writestr('a', '1')
archive.writestr('b', '2')
archive.writestr('c', '3')
archive.extractall()
os.chdir(str(tmpdir))
reset(path)
assert(set(os.listdir('.')) == {'foo.zip', 'a', 'b', 'c'})
@pytest.mark.parametrize('script', [
'unzip foo',
'unzip foo.zip'])
def test_match(zip_error, script):
assert match(Command(script=script), None)
@pytest.mark.parametrize('script', [
'unzip foo',
'unzip foo.zip'])
def test_side_effect(zip_error, script):
side_effect(Command(script=script), None)
assert(os.listdir('.') == ['foo.zip'])
@pytest.mark.parametrize('script,fixed', [
('unzip foo', 'unzip foo -d foo'),
('unzip foo.zip', 'unzip foo.zip -d foo')])
def test_get_new_command(zip_error, script, fixed):
assert get_new_command(Command(script=script), None) == fixed

View File

@@ -11,6 +11,14 @@ def test_match(command):
assert match(command, None)
@pytest.mark.parametrize('command', [
Command(script='mv foo bar/', stderr=""),
Command(script='mv foo bar/foo', stderr="mv: permission denied"),
])
def test_not_match(command):
assert not match(command, None)
@pytest.mark.parametrize('command, new_command', [
(Command(script='mv foo bar/foo', stderr="mv: cannot move 'foo' to 'bar/foo': No such file or directory"), 'mkdir -p bar && mv foo bar/foo'),
(Command(script='mv foo bar/', stderr="mv: cannot move 'foo' to 'bar/': No such file or directory"), 'mkdir -p bar && mv foo bar/'),

View File

@@ -0,0 +1,37 @@
import pytest
from thefuck.rules.tsuru_login import match, get_new_command
from tests.utils import Command
error_msg = (
"Error: you're not authenticated or your session has expired.",
("You're not authenticated or your session has expired. "
"Please use \"login\" command for authentication."),
)
@pytest.mark.parametrize('command', [
Command(script='tsuru app-shell', stderr=error_msg[0]),
Command(script='tsuru app-log -f', stderr=error_msg[1]),
])
def test_match(command):
assert match(command, {})
@pytest.mark.parametrize('command', [
Command(script='tsuru'),
Command(script='tsuru app-restart', stderr=('Error: unauthorized')),
Command(script='tsuru app-log -f', stderr=('Error: unparseable data')),
])
def test_not_match(command):
assert not match(command, {})
@pytest.mark.parametrize('command, new_command', [
(Command('tsuru app-shell', stderr=error_msg[0]),
'tsuru login && tsuru app-shell'),
(Command('tsuru app-log -f', stderr=error_msg[1]),
'tsuru login && tsuru app-log -f'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command, {}) == new_command

View File

@@ -14,7 +14,8 @@ def test_load_rule(mocker):
return_value=Mock(match=match,
get_new_command=get_new_command,
enabled_by_default=True,
priority=900))
priority=900,
requires_output=True))
assert main.load_rule(Path('/rules/bash.py')) \
== Rule('bash', match, get_new_command, priority=900)
load_source.assert_called_once_with('bash', '/rules/bash.py')
@@ -152,7 +153,7 @@ class TestConfirm(object):
def test_with_side_effect_and_without_confirmation(self, capsys):
assert main.confirm('command', Mock(), Mock(require_confirmation=False))
assert capsys.readouterr() == ('', 'command*\n')
assert capsys.readouterr() == ('', 'command (+side effect)\n')
# `stdin` fixture should be applied after `capsys`
def test_when_confirmation_required_and_confirmed(self, capsys, stdin):
@@ -164,7 +165,7 @@ class TestConfirm(object):
def test_when_confirmation_required_and_confirmed_with_side_effect(self, capsys, stdin):
assert main.confirm('command', Mock(), Mock(require_confirmation=True,
no_colors=True))
assert capsys.readouterr() == ('', 'command* [enter/ctrl+c]')
assert capsys.readouterr() == ('', 'command (+side effect) [enter/ctrl+c]')
def test_when_confirmation_required_and_aborted(self, capsys, stdin):
stdin.side_effect = KeyboardInterrupt

View File

@@ -10,7 +10,8 @@ def Rule(name='', match=lambda *_: True,
get_new_command=lambda *_: '',
enabled_by_default=True,
side_effect=None,
priority=DEFAULT_PRIORITY):
priority=DEFAULT_PRIORITY,
requires_output=True):
return types.Rule(name, match, get_new_command,
enabled_by_default, side_effect,
priority)
priority, requires_output)

View File

@@ -29,19 +29,19 @@ def rule_failed(rule, exc_info, settings):
def show_command(new_command, side_effect, settings):
sys.stderr.write('{bold}{command}{side_effect}{reset}\n'.format(
sys.stderr.write('{bold}{command}{reset}{side_effect}\n'.format(
command=new_command,
side_effect='*' if side_effect else '',
side_effect=' (+side effect)' if side_effect else '',
bold=color(colorama.Style.BRIGHT, settings),
reset=color(colorama.Style.RESET_ALL, settings)))
def confirm_command(new_command, side_effect, settings):
sys.stderr.write(
'{bold}{command}{side_effect}{reset} '
'{bold}{command}{reset}{side_effect} '
'[{green}enter{reset}/{red}ctrl+c{reset}]'.format(
command=new_command,
side_effect='*' if side_effect else '',
side_effect=' (+side effect)' if side_effect else '',
bold=color(colorama.Style.BRIGHT, settings),
green=color(colorama.Fore.GREEN, settings),
red=color(colorama.Fore.RED, settings),

View File

@@ -28,7 +28,8 @@ def load_rule(rule):
rule_module.get_new_command,
getattr(rule_module, 'enabled_by_default', True),
getattr(rule_module, 'side_effect', None),
getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY))
getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY),
getattr(rule_module, 'requires_output', True))
def _get_loaded_rules(rules, settings):
@@ -87,13 +88,26 @@ def get_command(settings, args):
settings):
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env)
if wait_output(settings, result):
return types.Command(script, result.stdout.read().decode('utf-8'),
result.stderr.read().decode('utf-8'))
stdout = result.stdout.read().decode('utf-8')
stderr = result.stderr.read().decode('utf-8')
logs.debug(u'Received stdout: {}'.format(stdout), settings)
logs.debug(u'Received stderr: {}'.format(stderr), settings)
return types.Command(script, stdout, stderr)
else:
logs.debug(u'Execution timed out!', settings)
return types.Command(script, None, None)
def get_matched_rule(command, rules, settings):
"""Returns first matched rule for command."""
script_only = command.stdout is None and command.stderr is None
for rule in rules:
if script_only and rule.requires_output:
continue
try:
with logs.debug_time(u'Trying rule: {};'.format(rule.name),
settings):
@@ -138,20 +152,16 @@ def main():
logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings)
command = get_command(settings, sys.argv)
if command:
logs.debug(u'Received stdout: {}'.format(command.stdout), settings)
logs.debug(u'Received stderr: {}'.format(command.stderr), settings)
rules = get_rules(user_dir, settings)
logs.debug(
u'Loaded rules: {}'.format(', '.join(rule.name for rule in rules)),
settings)
rules = get_rules(user_dir, settings)
logs.debug(
u'Loaded rules: {}'.format(', '.join(rule.name for rule in rules)),
settings)
matched_rule = get_matched_rule(command, rules, settings)
if matched_rule:
logs.debug(u'Matched rule: {}'.format(matched_rule.name), settings)
run_rule(matched_rule, command, settings)
return
matched_rule = get_matched_rule(command, rules, settings)
if matched_rule:
logs.debug(u'Matched rule: {}'.format(matched_rule.name), settings)
run_rule(matched_rule, command, settings)
return
logs.failed('No fuck given', settings)

View File

@@ -0,0 +1,41 @@
from thefuck import shells
import os
import tarfile
def _is_tar_extract(cmd):
if '--extract' in cmd:
return True
cmd = cmd.split()
return len(cmd) > 1 and 'x' in cmd[1]
def _tar_file(cmd):
tar_extentions = ('.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz',
'.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2',
'.tgz', '.tlz', '.txz', '.tz')
for c in cmd.split():
for ext in tar_extentions:
if c.endswith(ext):
return (c, c[0:len(c)-len(ext)])
def match(command, settings):
return (command.script.startswith('tar')
and '-C' not in command.script
and _is_tar_extract(command.script)
and _tar_file(command.script) is not None)
def get_new_command(command, settings):
return shells.and_('mkdir -p {dir}', '{cmd} -C {dir}') \
.format(dir=_tar_file(command.script)[1], cmd=command.script)
def side_effect(command, settings):
with tarfile.TarFile(_tar_file(command.script)[0]) as archive:
for file in archive.getnames():
os.remove(file)

View File

@@ -0,0 +1,39 @@
import os
import zipfile
def _is_bad_zip(file):
with zipfile.ZipFile(file, 'r') as archive:
return len(archive.namelist()) > 1
def _zip_file(command):
# unzip works that way:
# unzip [-flags] file[.zip] [file(s) ...] [-x file(s) ...]
# ^ ^ files to unzip from the archive
# archive to unzip
for c in command.script.split()[1:]:
if not c.startswith('-'):
if c.endswith('.zip'):
return c
else:
return '{}.zip'.format(c)
def match(command, settings):
return (command.script.startswith('unzip')
and '-d' not in command.script
and _is_bad_zip(_zip_file(command)))
def get_new_command(command, settings):
return '{} -d {}'.format(command.script, _zip_file(command)[:-4])
def side_effect(command, settings):
with zipfile.ZipFile(_zip_file(command), 'r') as archive:
for file in archive.namelist():
os.remove(file)
requires_output = False

View File

@@ -1,5 +1,4 @@
from thefuck import utils
from thefuck.shells import and_
from thefuck import utils, shells
from thefuck.utils import replace_argument
@@ -13,5 +12,5 @@ def match(command, settings):
@utils.git_support
def get_new_command(command, settings):
return and_(replace_argument(command.script, 'push', 'pull'),
command.script)
return shells.and_(replace_argument(command.script, 'push', 'pull'),
command.script)

View File

@@ -0,0 +1,11 @@
from thefuck import shells
def match(command, settings):
return (command.script.startswith('tsuru')
and 'not authenticated' in command.stderr
and 'session has expired' in command.stderr)
def get_new_command(command, settings):
return shells.and_('tsuru login', command.script)

View File

@@ -5,7 +5,7 @@ Command = namedtuple('Command', ('script', 'stdout', 'stderr'))
Rule = namedtuple('Rule', ('name', 'match', 'get_new_command',
'enabled_by_default', 'side_effect',
'priority'))
'priority', 'requires_output'))
class RulesNamesList(list):