Skip to content

Commit b433651

Browse files
committed
Remove environment-variable-based defaults in psql --help
This seemed inconsistent with the --help output of other tools. Depending on the values, it can cause ugly formatting. Also, we're not getting the defaults from libpq, we're just emulating the methods libpq uses to derive these values, so they might not be 100% correct. Author: Atsushi Torikoshi <torikoshia@oss.nttdata.com> Discussion: https://www.postgresql.org/message-id/flat/50ca8ff35a8dd8f9ec89963b503571a7@oss.nttdata.com
1 parent aec684f commit b433651

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/bin/psql/help.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,10 @@
5050
void
5151
usage(unsigned short int pager)
5252
{
53-
const char *env;
54-
const char *user;
55-
char *errstr;
5653
PQExpBufferData buf;
5754
int nlcount;
5855
FILE *output;
5956

60-
/* Find default user, in case we need it. */
61-
user = getenv("PGUSER");
62-
if (!user)
63-
{
64-
user = get_user_name(&errstr);
65-
if (!user)
66-
pg_fatal("%s", errstr);
67-
}
68-
6957
/*
7058
* To avoid counting the output lines manually, build the output in "buf"
7159
* and then count them.
@@ -77,13 +65,8 @@ usage(unsigned short int pager)
7765
HELP0(" psql [OPTION]... [DBNAME [USERNAME]]\n\n");
7866

7967
HELP0("General options:\n");
80-
/* Display default database */
81-
env = getenv("PGDATABASE");
82-
if (!env)
83-
env = user;
8468
HELP0(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n");
85-
HELPN(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n",
86-
env);
69+
HELP0(" -d, --dbname=DBNAME database name to connect to\n");
8770
HELP0(" -f, --file=FILENAME execute commands from file, then exit\n");
8871
HELP0(" -l, --list list available databases, then exit\n");
8972
HELP0(" -v, --set=, --variable=NAME=VALUE\n"
@@ -128,17 +111,9 @@ usage(unsigned short int pager)
128111
" set record separator for unaligned output to zero byte\n");
129112

130113
HELP0("\nConnection options:\n");
131-
/* Display default host */
132-
env = getenv("PGHOST");
133-
HELPN(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n",
134-
env ? env : _("local socket"));
135-
/* Display default port */
136-
env = getenv("PGPORT");
137-
HELPN(" -p, --port=PORT database server port (default: \"%s\")\n",
138-
env ? env : DEF_PGPORT_STR);
139-
/* Display default user */
140-
HELPN(" -U, --username=USERNAME database user name (default: \"%s\")\n",
141-
user);
114+
HELP0(" -h, --host=HOSTNAME database server host or socket directory\n");
115+
HELP0(" -p, --port=PORT database server port\n");
116+
HELP0(" -U, --username=USERNAME database user name\n");
142117
HELP0(" -w, --no-password never prompt for password\n");
143118
HELP0(" -W, --password force password prompt (should happen automatically)\n");
144119

0 commit comments

Comments
 (0)