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 poetry rule #1361

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ following rules are enabled by default:
* `pip_install` – fixes permission issues with `pip install` commands by adding `--user` or prepending `sudo` if necessary;
* `pip_unknown_command` – fixes wrong `pip` commands, for example `pip instatl/pip install`;
* `php_s` – replaces `-s` by `-S` when trying to run a local php server;
* `poetry` – reads help hints to guess what you meant;
* `port_already_in_use` – kills process that bound port;
* `prove_recursively` – adds `-r` when called with directory;
* `python_command` – prepends `python` when you try to run non-executable/without `./` python script;
Expand Down
32 changes: 32 additions & 0 deletions thefuck/rules/poetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# $ poetry updat
#
# The command "updat" does not exist.
#
# Did you mean one of these?
# update
# self update
#
# $ fuck
# poetry update [enter/↑/↓/ctrl+c]
#
import re
from thefuck.utils import for_app

REGEX = r"(?m)(?<=Did you mean one of these\?\n)(\s+(.+)$)+"


@for_app("poetry")
def match(command):
return "Did you mean one of these?" in command.output


def get_new_command(command) -> str | list[str]:
matches = re.search(REGEX, command.output)
if matches:
return [f"poetry {s.strip()}" for s in matches.group().split("\n")]
else:
return ""


enabled_by_default = True