On 2019-02-21 18:28, Peter Eisentraut wrote:
> => \h analyze

> URL: https://www.postgresql.org/docs/12/sql-analyze.html
> ^^^^

Here is a patch.

It doesn't deal with the "devel" paths yet.  Discussion there is still
ongoing a bit.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 962caa3b1a145c6f377f7e616515da5be864fcdc Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 25 Feb 2019 09:55:06 +0100
Subject: [PATCH v1] psql: Add URL to \help output

---
 src/bin/psql/create_help.pl | 10 ++++++++--
 src/bin/psql/help.c         |  7 +++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/create_help.pl b/src/bin/psql/create_help.pl
index 314bb5d87c..e8dd90d671 100644
--- a/src/bin/psql/create_help.pl
+++ b/src/bin/psql/create_help.pl
@@ -64,6 +64,7 @@
 {
        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 @@
 
 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 @@
          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 @@
        $filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is
          and $cmdsynopsis = $1;
 
-       if (@cmdnames && $cmddesc && $cmdsynopsis)
+       if (@cmdnames && $cmddesc && $cmdid && $cmdsynopsis)
        {
                s/\"/\\"/g foreach @cmdnames;
 
@@ -146,6 +150,7 @@
                foreach my $cmdname (@cmdnames)
                {
                        $entries{$cmdname} = {
+                               cmdid       => $cmdid,
                                cmddesc     => $cmddesc,
                                cmdsynopsis => $cmdsynopsis,
                                params      => \@params,
@@ -188,6 +193,7 @@
        $id =~ s/ /_/g;
        print $cfile_handle "    { \"$_\",
       N_(\"$entries{$_}{cmddesc}\"),
+      \"$entries{$_}{cmdid}\",
       sql_help_$id,
       $entries{$_}{nl_count} },
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 7c6fa2c590..4fbc4dde91 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -627,10 +627,13 @@ helpSQL(const char *topic, unsigned short int pager)
                                        help_found = true;
                                        fprintf(output, _("Command:     %s\n"
                                                                          
"Description: %s\n"
-                                                                         
"Syntax:\n%s\n\n"),
+                                                                         
"Syntax:\n%s\n\n"
+                                                                         "URL: 
https://www.postgresql.org/docs/%s/%s.html\n\n";),
                                                        QL_HELP[i].cmd,
                                                        _(QL_HELP[i].help),
-                                                       buffer.data);
+                                                       buffer.data,
+                                                       PG_MAJORVERSION,
+                                                       QL_HELP[i].docbook_id);
                                        /* If we have an exact match, exit.  
Fixes \h SELECT */
                                        if (pg_strcasecmp(topic, 
QL_HELP[i].cmd) == 0)
                                                break;
-- 
2.20.1

Reply via email to