mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
- Add: rules/go_unknown_command for misspelled go commands.
- Add: tests/test_go_unknown_command which tests match and mismatch case of rules/go_unknown_command. - Change: Added description of go_unknown_command to README.md.
This commit is contained in:
parent
01a5ba99d0
commit
7b66214894
@ -233,6 +233,7 @@ following rules are enabled by default:
|
||||
* `git_tag_force` – adds `--force` to `git tag <tagname>` when the tag already exists;
|
||||
* `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`;
|
||||
* `go_run` – appends `.go` extension when compiling/running Go programs;
|
||||
* `go_unknown_command` – fixes wrong `go` commands, for example `go bulid`;
|
||||
* `gradle_no_task` – fixes not found or ambiguous `gradle` task;
|
||||
* `gradle_wrapper` – replaces `gradle` with `./gradlew`;
|
||||
* `grep_arguments_order` – fixes `grep` arguments order for situations like `grep -lir . test`;
|
||||
|
13
tests/rules/test_go_unknown_command.py
Normal file
13
tests/rules/test_go_unknown_command.py
Normal file
@ -0,0 +1,13 @@
|
||||
from thefuck.rules.go_unknown_command import match
|
||||
from thefuck.types import Command
|
||||
|
||||
_GO_BUILD_MISSPELLED_OUTPUT = """go bulid: unknown command
|
||||
Run 'go help' for usage."""
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Command('go bulid', _GO_BUILD_MISSPELLED_OUTPUT))
|
||||
|
||||
|
||||
def test_not_match():
|
||||
assert not match(Command('go run', 'go run: no go files listed'))
|
18
thefuck/rules/go_unknown_command.py
Normal file
18
thefuck/rules/go_unknown_command.py
Normal file
@ -0,0 +1,18 @@
|
||||
from thefuck.utils import get_closest, replace_argument
|
||||
|
||||
_GOLANG_COMMANDS = (
|
||||
"bug", "build", "clean", "doc", "env", "fix", "fmt", "generate", "get",
|
||||
"install", "list", "mod", "run", "test", "tool", "version", "vet")
|
||||
|
||||
|
||||
def match(command):
|
||||
return (command.script_parts
|
||||
and command.script_parts[0] == "go"
|
||||
and 'unknown command' in command.output)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
closest_subcommand = get_closest(command.script_parts[1],
|
||||
_GOLANG_COMMANDS)
|
||||
return replace_argument(command.script, command.script_parts[1],
|
||||
closest_subcommand)
|
Loading…
x
Reference in New Issue
Block a user