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
Iryna's Editor Command PR #217
Conversation
Looks good. Thanks! How did you do that? I could not figure it out! |
|
Steps to reproduce:
TADA! There are many ways to achieve the same result, so if someone has a better way to do this, let me know. |
@@ -1,6 +1,7 @@ | |||
from __future__ import print_function | |||
import sys | |||
import logging | |||
import click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling in click as a dependency seems wrong to me. I'll explain the reasons in a longer comment.
Longer comment as promised:
I'm sorry about sending this negative comment later on in the review. I should have caught this at the early stage. :( I'm open to discussing this decision to keep pgspecial.py a standalone. |
Ok. I didn't know this was the intent. I agree that even though "external editor" is also a special command because it's a backslash command, it does not fit between the rest of them that follow the pattern of "run some specific Postgres queries and return data". I see two ways of solving this:
What do you think? |
It's admirable to have a goal to keep main.py as clean as possible and not deal with commands at all. But I've already set the precedent (a wrong one) to deal with |
Then I will move both \c and \e there. |
@amjith So looks like \c has too much going on (setting internal state of pgexecute) to pull it out. But editor command is now separate from the pgspecial. Perhaps you can add https://github.com/j-bennet/pgcli/commit/9c215d25ea9d3d523929e6d58141e73b9f76fd99 to this PR. |
|
Is this an external editor command? | ||
:param command: string | ||
""" | ||
return command.strip().startswith('\e') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to endswith('\e')
.
@amjith I already looked into changing this to "endswith", and it's not as simple as it seems. I'll explain later if you like, but it seems that it would require some more significant changes in main module. I was thinking perhaps this (smaller) change can be implementation stage 1, and I can add a stage 2 later. |
I've added a new commit to do what I had in mind. You're right it wasn't as straight forward as I explained in the comments. So would yo mind reviewing the latest commit? I've checked it manually and it seems to work as expected. |
|
@amjith Interesting... I remember seeing some odd behavior when I changed this to "endswith", in multiline mode it didn't accept "select *\e", and wanted ";". I had to invent a workaround for that. I have no time to look now, but will check later. |
@amjith I don't see that weird behavior anymore, seems to work fine. I'll check on mac (only verified on linux), but I think you're good to go. |
That is a good catch. I'm surprised that it didn't happen in Linux. I know the reason why. I'll have to think about a good way to fix it. |
|
While adding the multi-line case I discovered another corner case for Details: https://github.com/dbcli/pgcli/pull/217/files#diff-38f3aeda57742756afa677ca09dcea43R205 I've refactored the code. It probably needs more tests. But I'd appreciate another pair of eyes to check my work. |
|
|
# The reason we can't simply do .strip('\e') is that it strips characters, | ||
# not a substring. So it'll strip "e" in the end of the sql also! | ||
# Ex: "select * from style\e" -> "select * from styl". | ||
pattern = re.compile('(^\\\e|\\\e$)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. 👍
Thank you for working with me on this PR. It was one of the tough commands with various corner cases. 🔑 |
This PR is a cleanup of #213 to remove extraneous commits added in due to the repo move.
I've cleaned up the commit history. I should have waited to move the repo after merging all pending PRs. That was my bad.
@j-bennet Doe this look good?
I'll review the changes and merge it in.