mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
Add: get_golang_commands which dynamically gets golang possible commands.
This commit is contained in:
parent
5b59e2c32a
commit
5aca24537a
@ -1,8 +1,20 @@
|
|||||||
from thefuck.utils import get_closest, replace_argument, for_app
|
from itertools import dropwhile, islice, takewhile
|
||||||
|
import subprocess
|
||||||
|
|
||||||
_GOLANG_COMMANDS = (
|
from thefuck.utils import get_closest, replace_argument, for_app, which, cache
|
||||||
"bug", "build", "clean", "doc", "env", "fix", "fmt", "generate", "get",
|
|
||||||
"install", "list", "mod", "run", "test", "tool", "version", "vet")
|
|
||||||
|
def get_golang_commands():
|
||||||
|
proc = subprocess.Popen('go', stderr=subprocess.PIPE)
|
||||||
|
lines = [line.decode('utf-8').strip() for line in proc.stderr.readlines()]
|
||||||
|
lines = dropwhile(lambda line: line != 'The commands are:', lines)
|
||||||
|
lines = islice(lines, 2, None)
|
||||||
|
lines = takewhile(lambda line: line, lines)
|
||||||
|
return [line.split(' ')[0] for line in lines]
|
||||||
|
|
||||||
|
|
||||||
|
if which('go'):
|
||||||
|
get_docker_commands = cache(which('go'))(get_golang_commands())
|
||||||
|
|
||||||
|
|
||||||
@for_app('go')
|
@for_app('go')
|
||||||
@ -11,7 +23,6 @@ def match(command):
|
|||||||
|
|
||||||
|
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
closest_subcommand = get_closest(command.script_parts[1],
|
closest_subcommand = get_closest(command.script_parts[1], get_golang_commands())
|
||||||
_GOLANG_COMMANDS)
|
|
||||||
return replace_argument(command.script, command.script_parts[1],
|
return replace_argument(command.script, command.script_parts[1],
|
||||||
closest_subcommand)
|
closest_subcommand)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user