Remove environment-variable-based defaults in psql --help
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 6 Oct 2023 08:55:10 +0000 (10:55 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 6 Oct 2023 09:54:36 +0000 (11:54 +0200)
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

src/bin/psql/help.c

index 12280c0e541106b6a21c395aae14c484a3802132..3b2d59e2eea3669f2429950ade22420b27cb97c4 100644 (file)
 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");