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
This commit is contained in:
Peter Eisentraut 2023-10-06 10:55:10 +02:00
parent aec684ff0f
commit b4336515b0

View File

@ -50,22 +50,10 @@
void
usage(unsigned short int pager)
{
const char *env;
const char *user;
char *errstr;
PQExpBufferData buf;
int nlcount;
FILE *output;
/* Find default user, in case we need it. */
user = getenv("PGUSER");
if (!user)
{
user = get_user_name(&errstr);
if (!user)
pg_fatal("%s", errstr);
}
/*
* To avoid counting the output lines manually, build the output in "buf"
* and then count them.
@ -77,13 +65,8 @@ usage(unsigned short int pager)
HELP0(" psql [OPTION]... [DBNAME [USERNAME]]\n\n");
HELP0("General options:\n");
/* Display default database */
env = getenv("PGDATABASE");
if (!env)
env = user;
HELP0(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n");
HELPN(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n",
env);
HELP0(" -d, --dbname=DBNAME database name to connect to\n");
HELP0(" -f, --file=FILENAME execute commands from file, then exit\n");
HELP0(" -l, --list list available databases, then exit\n");
HELP0(" -v, --set=, --variable=NAME=VALUE\n"
@ -128,17 +111,9 @@ usage(unsigned short int pager)
" set record separator for unaligned output to zero byte\n");
HELP0("\nConnection options:\n");
/* Display default host */
env = getenv("PGHOST");
HELPN(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n",
env ? env : _("local socket"));
/* Display default port */
env = getenv("PGPORT");
HELPN(" -p, --port=PORT database server port (default: \"%s\")\n",
env ? env : DEF_PGPORT_STR);
/* Display default user */
HELPN(" -U, --username=USERNAME database user name (default: \"%s\")\n",
user);
HELP0(" -h, --host=HOSTNAME database server host or socket directory\n");
HELP0(" -p, --port=PORT database server port\n");
HELP0(" -U, --username=USERNAME database user name\n");
HELP0(" -w, --no-password never prompt for password\n");
HELP0(" -W, --password force password prompt (should happen automatically)\n");