Allow 'help' in psql to show \? help, for novice assistance.
authorBruce Momjian <bruce@momjian.us>
Fri, 4 Apr 2008 17:42:43 +0000 (17:42 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 4 Apr 2008 17:42:43 +0000 (17:42 +0000)
Greg Sabino Mullane

src/bin/psql/help.c
src/bin/psql/mainloop.c

index 8d3b24368ddf55f3dcba2e3212315fb46a86d368..792c4eea22b643394bd41cd0c3f29c4954299242 100644 (file)
@@ -188,6 +188,7 @@ slashUsage(unsigned short int pager)
                        ON(pset.timing));
        fprintf(output, _("  \\unset NAME    unset (delete) internal variable\n"));
        fprintf(output, _("  \\! [COMMAND]   execute command in shell or start interactive shell\n"));
+       fprintf(output, _("  \\?             display this help output\n"));
        fprintf(output, "\n");
 
        fprintf(output, _("Query Buffer\n"));
index 5ea3cfd8c8b3102336d007375e5737a73411822b..ab0743a853df4e4bf63825a2065a3a03eb9d4727 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "command.h"
 #include "common.h"
+#include "help.h"
 #include "input.h"
 #include "settings.h"
 
@@ -171,6 +172,16 @@ MainLoop(FILE *source)
                        continue;
                }
 
+               /* A request for help? Be friendly and show them the slash way of doing things */
+               if (pset.cur_cmd_interactive && query_buf->len == 0 &&
+                       pg_strncasecmp(line, "help", 4) == 0 &&
+                       (line[4] == '\0' || line[4] == ';' || isspace(line[4])))
+               {
+                       free(line);
+                       slashUsage(pset.popt.topt.pager);
+                       continue;
+               }
+
                /* echo back if flag is set */
                if (pset.echo == PSQL_ECHO_ALL && !pset.cur_cmd_interactive)
                        puts(line);