1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#728: Add heroku_multiple_apps rule (#729)

Closes https://github.com/nvbn/thefuck/issues/728
This commit is contained in:
Joseph Frazier 2017-11-09 18:42:23 -05:00 committed by GitHub
parent 8fb5ddefb6
commit 10ac1a3b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 0 deletions

View File

@ -218,6 +218,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `grunt_task_not_found` – fixes misspelled `grunt` commands;
* `gulp_not_task` – fixes misspelled `gulp` tasks;
* `has_exists_script` – prepends `./` when script/binary exists;
* `heroku_multiple_apps` &ndash; add `--app <app>` to `heroku` commands like `heroku pg`;
* `heroku_not_command` &ndash; fixes wrong `heroku` commands like `heroku log`;
* `history` &ndash; tries to replace command with most similar command from history;
* `hostscli` &ndash; tries to fix `hostscli` usage;

View File

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
import pytest
from thefuck.types import Command
from thefuck.rules.heroku_multiple_apps import match, get_new_command
suggest_output = '''
Multiple apps in git remotes
Usage: --remote heroku-dev
or: --app myapp-dev
Your local git repository has more than 1 app referenced in git remotes.
Because of this, we can't determine which app you want to run this command against.
Specify the app you want with --app or --remote.
Heroku remotes in repo:
myapp (heroku)
myapp-dev (heroku-dev)
https://devcenter.heroku.com/articles/multiple-environments
'''
not_match_output = '''
=== HEROKU_POSTGRESQL_TEAL_URL, DATABASE_URL
Plan: Hobby-basic
Status: Available
Connections: 20/20
PG Version: 9.6.4
Created: 2017-01-01 00:00 UTC
Data Size: 99.9 MB
Tables: 99
Rows: 12345/10000000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-round-12345
'''
@pytest.mark.parametrize('cmd', ['pg'])
def test_match(cmd):
assert match(
Command('heroku {}'.format(cmd), suggest_output))
@pytest.mark.parametrize('script, output', [
('heroku pg', not_match_output)])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('cmd, result', [
('pg', ['heroku pg --app myapp', 'heroku pg --app myapp-dev'])])
def test_get_new_command(cmd, result):
command = Command('heroku {}'.format(cmd), suggest_output)
assert get_new_command(command) == result

View File

@ -0,0 +1,12 @@
import re
from thefuck.utils import for_app
@for_app('heroku')
def match(command):
return 'https://devcenter.heroku.com/articles/multiple-environments' in command.output
def get_new_command(command):
apps = re.findall('([^ ]*) \([^)]*\)', command.output)
return [command.script + ' --app ' + app for app in apps]