]> granicus.if.org Git - postgresql/commitdiff
psql: Add documentation URL to \help output
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 11 Mar 2019 07:50:02 +0000 (08:50 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 11 Mar 2019 08:11:37 +0000 (09:11 +0100)
Add a link to the specific command's reference web page to the bottom
of its \help output.

Discussion: https://www.postgresql.org/message-id/flat/40179bd0-fa7d-4108-1991-a20ae9ad5667%402ndquadrant.com

src/bin/psql/create_help.pl
src/bin/psql/help.c

index 96cf3d37ef01ca8b82f6a738a28fe8101b28bcef..d8e6671e6893ee0510584f6dfe42eab25faa120e 100644 (file)
@@ -64,6 +64,7 @@ struct _helpStruct
 {
        const char         *cmd;                /* the command name */
        const char         *help;               /* the help associated with it */
+       const char         *docbook_id; /* DocBook XML id (for generating URL) */
        void (*syntaxfunc)(PQExpBuffer);        /* function that prints the syntax associated with it */
        int                             nl_count;       /* number of newlines in syntax (for pager) */
 };
@@ -92,7 +93,7 @@ my %entries;
 
 foreach my $file (sort readdir DIR)
 {
-       my (@cmdnames, $cmddesc, $cmdsynopsis);
+       my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis);
        $file =~ /\.sgml$/ or next;
 
        open(my $fh, '<', "$docdir/$file") or next;
@@ -104,6 +105,9 @@ foreach my $file (sort readdir DIR)
          m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
          or next;
 
+       $filecontent =~ m!<refentry id="([a-z-]+)">!
+         and $cmdid = $1;
+
        # Collect multiple refnames
   LOOP:
        {
@@ -116,7 +120,7 @@ foreach my $file (sort readdir DIR)
        $filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is
          and $cmdsynopsis = $1;
 
-       if (@cmdnames && $cmddesc && $cmdsynopsis)
+       if (@cmdnames && $cmddesc && $cmdid && $cmdsynopsis)
        {
                s/\"/\\"/g foreach @cmdnames;
 
@@ -144,6 +148,7 @@ foreach my $file (sort readdir DIR)
                foreach my $cmdname (@cmdnames)
                {
                        $entries{$cmdname} = {
+                               cmdid       => $cmdid,
                                cmddesc     => $cmddesc,
                                cmdsynopsis => $cmdsynopsis,
                                params      => \@params,
@@ -186,6 +191,7 @@ foreach (sort keys %entries)
        $id =~ s/ /_/g;
        print $cfile_handle "    { \"$_\",
       N_(\"$entries{$_}{cmddesc}\"),
+      \"$entries{$_}{cmdid}\",
       sql_help_$id,
       $entries{$_}{nl_count} },
 
index 6bac9e47fd7c42ba6b720ff1775de90f7dffe999..6fc4ebab1e8205f2f1ecba208f98e55c51ad1fb8 100644 (file)
@@ -623,16 +623,23 @@ helpSQL(const char *topic, unsigned short int pager)
                                        strcmp(topic, "*") == 0)
                                {
                                        PQExpBufferData buffer;
+                                       char       *url;
 
                                        initPQExpBuffer(&buffer);
                                        QL_HELP[i].syntaxfunc(&buffer);
                                        help_found = true;
+                                       url = psprintf("https://www.postgresql.org/docs/%s/%s.html",
+                                                                  strstr(PG_VERSION, "devel") ? "devel" : PG_MAJORVERSION,
+                                                                  QL_HELP[i].docbook_id);
                                        fprintf(output, _("Command:     %s\n"
                                                                          "Description: %s\n"
-                                                                         "Syntax:\n%s\n\n"),
+                                                                         "Syntax:\n%s\n\n"
+                                                                         "URL: %s\n\n"),
                                                        QL_HELP[i].cmd,
                                                        _(QL_HELP[i].help),
-                                                       buffer.data);
+                                                       buffer.data,
+                                                       url);
+                                       free(url);
                                        /* If we have an exact match, exit.  Fixes \h SELECT */
                                        if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
                                                break;