X Tutup
The Wayback Machine - https://web.archive.org/web/20200612074508/https://github.com/dbcli/pgcli/issues/964
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

\h shows first octet of IP address #964

Open
thorstenkampe opened this issue Nov 3, 2018 · 2 comments
Open

\h shows first octet of IP address #964

thorstenkampe opened this issue Nov 3, 2018 · 2 comments
Labels

Comments

@thorstenkampe
Copy link

@thorstenkampe thorstenkampe commented Nov 3, 2018

Pgcli shows the first octet of an IP address ("127" for example) when giving an IP address as host name. The \h variable ("Short hostname of the server (up to first '.')" is part of the default prompt. Since IP addresses don't have a short form, this should probably be the full IP address.

Psql shows the same behaviour (in case you aim for consistency with psql even in incorrect cases)

pgcli postgresql://postgres:password@127.0.0.1
Server: PostgreSQL 11.0
Version: 2.0.0
[...]
postgres@127:5432/postgres dbcli>
@j-bennet j-bennet added bug easy labels Nov 3, 2018
@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Nov 3, 2018

This sounds like an unintentional side effect of "shortening" host names. In many cases, such as AWS EC2 host names (example: ec2-55-111-222-333.compute-1.amazonaws.com), we want to trim those redundant / repetitive suffixes to display a smaller prompt. Does not work great for IP addresses though.

@thorstenkampe
Copy link
Author

@thorstenkampe thorstenkampe commented Nov 4, 2018

A patch for the issue below.

Please note that this aims to be a very simple solution: a name like 123.456.com would not be shortened to 123.

Numeric host (and domain) names are legal (except for the top level domain). Nevertheless numeric host names are very rare and entering IP addresses for the host connection is common.

Taking care of the 123.456.com case would make the code more difficult to understand and verify (by using regular expressions or testing the right hand side of the host name while making sure it's not already a short name).

@@ -893,6 +893,8 @@
         host = self.pgexecute.host or '(none)'
         string = string.replace('\\H', host)
         short_host, _, _ = host.partition('.')
+        if short_host.isdigit():
+            short_host = host
         string = string.replace('\\h', short_host)
         string = string.replace('\\d', self.pgexecute.dbname or '(none)')
         string = string.replace('\\p', str(self.pgexecute.port) or '(none)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup