From 1d2d907c60a43ef31a147648d0a6cdc744f50b47 Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Tue, 2 Jun 2015 12:05:47 +0800 Subject: [PATCH 1/2] Added go_run rule --- tests/rules/test_go_run.py | 17 +++++++++++++++++ thefuck/rules/go_run.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/rules/test_go_run.py create mode 100644 thefuck/rules/go_run.py diff --git a/tests/rules/test_go_run.py b/tests/rules/test_go_run.py new file mode 100644 index 0000000..0574505 --- /dev/null +++ b/tests/rules/test_go_run.py @@ -0,0 +1,17 @@ +import pytest +from thefuck.rules.go_run import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='go run foo'), + Command(script='go run bar')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('go run foo'), 'go run foo.go'), + (Command('go run bar'), 'go run bar.go')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/go_run.py b/thefuck/rules/go_run.py new file mode 100644 index 0000000..79eedc5 --- /dev/null +++ b/thefuck/rules/go_run.py @@ -0,0 +1,14 @@ +# Appends .go when compiling go files +# +# Example: +# > go run foo +# error: go run: no go files listed +# +# + +def match(command, settings): + return (command.script.startswith ('go run ') + and not command.script.endswith('.go')) + +def get_new_command(command, settings): + return command.script + '.go' From c08182509dbf4913288b389577a2e07c5f010077 Mon Sep 17 00:00:00 2001 From: Camille Diez Date: Tue, 2 Jun 2015 12:08:28 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c36aa5a..ece6d66 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_pull` – sets upstream before executing previous `git pull`; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; * `git_stash` – stashes you local modifications before rebasing or switching branch; +* `go_run` – appends `.go` extension when compiling/running Go programs * `grep_recursive` – adds `-r` when you trying to grep directory; * `has_exists_script` – prepends `./` when script/binary exists; * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;