From 00d5ad7ecec8466432d4f123618072f8411bb7de Mon Sep 17 00:00:00 2001 From: Ryan Delaney Date: Tue, 7 Mar 2023 10:16:17 -0500 Subject: [PATCH 1/2] Add rule to use terraform help text for suggestions --- thefuck/rules/terraform_help.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 thefuck/rules/terraform_help.py diff --git a/thefuck/rules/terraform_help.py b/thefuck/rules/terraform_help.py new file mode 100644 index 0000000..4ed3c87 --- /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 | list[str]: + matches = re.search(REGEX, command.output) + if matches: + return f"""terraform {matches.groupdict().get("suggestion", "")}""" + else: + return "" + + +enabled_by_default = True From 022014298aa6205fe939653ee791f145a4495f52 Mon Sep 17 00:00:00 2001 From: Ryan Delaney Date: Tue, 7 Mar 2023 10:18:52 -0500 Subject: [PATCH 2/2] Fix type annotation Lists cannot be returned from this version --- thefuck/rules/terraform_help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thefuck/rules/terraform_help.py b/thefuck/rules/terraform_help.py index 4ed3c87..0489cda 100644 --- a/thefuck/rules/terraform_help.py +++ b/thefuck/rules/terraform_help.py @@ -23,7 +23,7 @@ def match(command) -> bool: ) -def get_new_command(command) -> str | list[str]: +def get_new_command(command) -> str: matches = re.search(REGEX, command.output) if matches: return f"""terraform {matches.groupdict().get("suggestion", "")}"""