mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Add aws cli rule
This rule corrects spelling mistakes for aws cli commands and subcommands.
This commit is contained in:
parent
bcc11219e6
commit
7bf405e9c3
@ -145,6 +145,7 @@ sudo -H pip install thefuck --upgrade
|
|||||||
The Fuck tries to match a rule for the previous command, creates a new command
|
The Fuck tries to match a rule for the previous command, creates a new command
|
||||||
using the matched rule and runs it. Rules enabled by default are as follows:
|
using the matched rule and runs it. Rules enabled by default are as follows:
|
||||||
|
|
||||||
|
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`
|
||||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||||
|
101
tests/rules/test_aws_cli.py
Normal file
101
tests/rules/test_aws_cli.py
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from thefuck.rules.aws_cli import match, get_new_command
|
||||||
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
|
no_suggestions = '''\
|
||||||
|
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
|
||||||
|
To see help text, you can run:
|
||||||
|
|
||||||
|
aws help
|
||||||
|
aws <command> help
|
||||||
|
aws <command> <subcommand> help
|
||||||
|
aws: error: argument command: Invalid choice, valid choices are:
|
||||||
|
|
||||||
|
dynamodb | dynamodbstreams
|
||||||
|
ec2 | ecr
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
misspelled_command = '''\
|
||||||
|
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
|
||||||
|
To see help text, you can run:
|
||||||
|
|
||||||
|
aws help
|
||||||
|
aws <command> help
|
||||||
|
aws <command> <subcommand> help
|
||||||
|
aws: error: argument command: Invalid choice, valid choices are:
|
||||||
|
|
||||||
|
dynamodb | dynamodbstreams
|
||||||
|
ec2 | ecr
|
||||||
|
|
||||||
|
|
||||||
|
Invalid choice: 'dynamdb', maybe you meant:
|
||||||
|
|
||||||
|
* dynamodb
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
misspelled_subcommand = '''\
|
||||||
|
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
|
||||||
|
To see help text, you can run:
|
||||||
|
|
||||||
|
aws help
|
||||||
|
aws <command> help
|
||||||
|
aws <command> <subcommand> help
|
||||||
|
aws: error: argument operation: Invalid choice, valid choices are:
|
||||||
|
|
||||||
|
query | scan
|
||||||
|
update-item | update-table
|
||||||
|
|
||||||
|
|
||||||
|
Invalid choice: 'scn', maybe you meant:
|
||||||
|
|
||||||
|
* scan
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
misspelled_subcommand_with_multiple_options = '''\
|
||||||
|
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
|
||||||
|
To see help text, you can run:
|
||||||
|
|
||||||
|
aws help
|
||||||
|
aws <command> help
|
||||||
|
aws <command> <subcommand> help
|
||||||
|
aws: error: argument operation: Invalid choice, valid choices are:
|
||||||
|
|
||||||
|
describe-table | get-item
|
||||||
|
list-tables | put-item
|
||||||
|
|
||||||
|
|
||||||
|
Invalid choice: 't-item', maybe you meant:
|
||||||
|
|
||||||
|
* put-item
|
||||||
|
* get-item
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command('aws dynamdb scan', stderr=misspelled_command),
|
||||||
|
Command('aws dynamodb scn', stderr=misspelled_subcommand),
|
||||||
|
Command('aws dynamodb t-item',
|
||||||
|
stderr=misspelled_subcommand_with_multiple_options)])
|
||||||
|
def test_match(command):
|
||||||
|
assert match(command)
|
||||||
|
|
||||||
|
|
||||||
|
def test_not_match():
|
||||||
|
assert not match(Command('aws dynamodb invalid', stderr=no_suggestions))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command, result', [
|
||||||
|
(Command('aws dynamdb scan', stderr=misspelled_command),
|
||||||
|
['aws dynamodb scan']),
|
||||||
|
(Command('aws dynamodb scn', stderr=misspelled_subcommand),
|
||||||
|
['aws dynamodb scan']),
|
||||||
|
(Command('aws dynamodb t-item',
|
||||||
|
stderr=misspelled_subcommand_with_multiple_options),
|
||||||
|
['aws dynamodb put-item', 'aws dynamodb get-item'])])
|
||||||
|
def test_get_new_command(command, result):
|
||||||
|
assert get_new_command(command) == result
|
17
thefuck/rules/aws_cli.py
Normal file
17
thefuck/rules/aws_cli.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from thefuck.utils import for_app, replace_argument
|
||||||
|
|
||||||
|
INVALID_CHOICE = "(?<=Invalid choice: ')(.*)(?=', maybe you meant:)"
|
||||||
|
OPTIONS = "^\s*\*\s(.*)"
|
||||||
|
|
||||||
|
|
||||||
|
@for_app('aws')
|
||||||
|
def match(command):
|
||||||
|
return "usage:" in command.stderr and "maybe you meant:" in command.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command):
|
||||||
|
mistake = re.search(INVALID_CHOICE, command.stderr).group(0)
|
||||||
|
options = re.findall(OPTIONS, command.stderr, flags=re.MULTILINE)
|
||||||
|
return [replace_argument(command.script, mistake, o) for o in options]
|
Loading…
x
Reference in New Issue
Block a user