Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to use terraform help text for suggestions #1366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions thefuck/rules/terraform_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# $ terraform destory
#
# Terraform has no command named "destory". Did you mean "destroy"?
#
# $ fuck
# terraform destroy [enter/↑/↓/ctrl+c]
#
import re
from thefuck.utils import for_app

REGEX = (
r"Terraform has no command named \".+?\"\. "
r"Did you mean \"(?P<suggestion>.+)\"\?"
)


@for_app("terraform")
def match(command) -> bool:
return (
"Terraform has no command named" in command.output
and "Did you mean" in command.output
)


def get_new_command(command) -> str:
matches = re.search(REGEX, command.output)
if matches:
return f"""terraform {matches.groupdict().get("suggestion", "")}"""
else:
return ""


enabled_by_default = True