diff --git a/thefuck/rules/terraform_help.py b/thefuck/rules/terraform_help.py new file mode 100644 index 000000000..0489cda22 --- /dev/null +++ b/thefuck/rules/terraform_help.py @@ -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.+)\"\?" +) + + +@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