1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

Merge 7ca0919e70fe23a551b2388c050aa34925c09d0c into c7e7e1d884d3bb241ea6448f72a989434c2a35ec

This commit is contained in:
Ronan Doolan 2024-05-11 07:31:43 +08:00 committed by GitHub
commit 9312fabd69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 0 deletions

View File

@ -228,6 +228,7 @@ following rules are enabled by default:
* `fab_command_not_found` – fixes misspelled fabric commands;
* `fix_alt_space` – replaces Alt+Space with Space character;
* `fix_file` – opens a file with an error in your `$EDITOR`;
* `gcloud_cli` – fixes misspelled commands like `gcloud comute instance list`;
* `gem_unknown_command` – fixes wrong `gem` commands;
* `git_add` – fixes *"pathspec 'foo' did not match any file(s) known to git."*;
* `git_add_force` &ndash; adds `--force` to `git add <pathspec>...` when paths are .gitignore'd;

View File

@ -0,0 +1,58 @@
import pytest
from thefuck.rules.gcloud_cli import match, get_new_command
from thefuck.types import Command
no_suggestions = '''\
ERROR: (gcloud) Command name argument expected.
'''
misspelled_command = '''\
ERROR: (gcloud) Invalid choice: 'comute'.
Usage: gcloud [optional flags] <group | command>
group may be access-context-manager | ai-platform | alpha | app |
asset | auth | beta | bigtable | builds | components |
composer | compute | config | container | dataflow |
dataproc | datastore | debug | deployment-manager |
dns | domains | endpoints | filestore | firebase |
functions | iam | iot | kms | logging | ml |
ml-engine | organizations | projects | pubsub | redis |
resource-manager | scheduler | services | source |
spanner | sql | tasks | topic
command may be docker | feedback | help | info | init | version
For detailed information on this command and its flags, run:
gcloud --help
'''
misspelled_subcommand = '''\
ERROR: (gcloud.compute) Invalid choice: 'instance'.
Maybe you meant:
gcloud compute instance-groups
gcloud compute instance-templates
gcloud compute instances
gcloud compute target-instances
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
'''
@pytest.mark.parametrize('command', [
Command('gcloud comute instances list', misspelled_subcommand),
Command('gcloud compute instance list', misspelled_subcommand)])
def test_match(command):
assert match(command)
def test_not_match():
assert not match(Command('aws dynamodb invalid', no_suggestions))
@pytest.mark.parametrize('command, result', [
(Command('gcloud comute instances list', misspelled_subcommand),
['gcloud compute instance-groups']),
(Command('gcloud compute instance list', misspelled_subcommand),
['gcloud compute instance-groups'])])
def test_get_new_command(command, result):
assert get_new_command(command) == result

View File

@ -0,0 +1,16 @@
import re
from thefuck.utils import for_app
INVALID_CHOICE = "(?<=Invalid choice: ')(.*)(?='.)"
OPTIONS = "t\\:\\n\\s\\s(.*)"
@for_app('gcloud')
def match(command):
return "ERROR:" in command.output and "Maybe you meant:" in command.output
def get_new_command(command):
options = re.findall(OPTIONS, command.output, flags=re.MULTILINE)
return options