Skip to content

Commit 27f3dea

Browse files
committed
psql: Add documentation URL to \help output
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
1 parent f2d84a4 commit 27f3dea

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/bin/psql/create_help.pl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
{
6565
const char *cmd; /* the command name */
6666
const char *help; /* the help associated with it */
67+
const char *docbook_id; /* DocBook XML id (for generating URL) */
6768
void (*syntaxfunc)(PQExpBuffer); /* function that prints the syntax associated with it */
6869
int nl_count; /* number of newlines in syntax (for pager) */
6970
};
@@ -92,7 +93,7 @@
9293

9394
foreach my $file (sort readdir DIR)
9495
{
95-
my (@cmdnames, $cmddesc, $cmdsynopsis);
96+
my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis);
9697
$file =~ /\.sgml$/ or next;
9798

9899
open(my $fh, '<', "$docdir/$file") or next;
@@ -104,6 +105,9 @@
104105
m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
105106
or next;
106107

108+
$filecontent =~ m!<refentry id="([a-z-]+)">!
109+
and $cmdid = $1;
110+
107111
# Collect multiple refnames
108112
LOOP:
109113
{
@@ -116,7 +120,7 @@
116120
$filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is
117121
and $cmdsynopsis = $1;
118122

119-
if (@cmdnames && $cmddesc && $cmdsynopsis)
123+
if (@cmdnames && $cmddesc && $cmdid && $cmdsynopsis)
120124
{
121125
s/\"/\\"/g foreach @cmdnames;
122126

@@ -144,6 +148,7 @@
144148
foreach my $cmdname (@cmdnames)
145149
{
146150
$entries{$cmdname} = {
151+
cmdid => $cmdid,
147152
cmddesc => $cmddesc,
148153
cmdsynopsis => $cmdsynopsis,
149154
params => \@params,
@@ -186,6 +191,7 @@
186191
$id =~ s/ /_/g;
187192
print $cfile_handle " { \"$_\",
188193
N_(\"$entries{$_}{cmddesc}\"),
194+
\"$entries{$_}{cmdid}\",
189195
sql_help_$id,
190196
$entries{$_}{nl_count} },
191197

src/bin/psql/help.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,23 @@ helpSQL(const char *topic, unsigned short int pager)
623623
strcmp(topic, "*") == 0)
624624
{
625625
PQExpBufferData buffer;
626+
char *url;
626627

627628
initPQExpBuffer(&buffer);
628629
QL_HELP[i].syntaxfunc(&buffer);
629630
help_found = true;
631+
url = psprintf("https://www.postgresql.org/docs/%s/%s.html",
632+
strstr(PG_VERSION, "devel") ? "devel" : PG_MAJORVERSION,
633+
QL_HELP[i].docbook_id);
630634
fprintf(output, _("Command: %s\n"
631635
"Description: %s\n"
632-
"Syntax:\n%s\n\n"),
636+
"Syntax:\n%s\n\n"
637+
"URL: %s\n\n"),
633638
QL_HELP[i].cmd,
634639
_(QL_HELP[i].help),
635-
buffer.data);
640+
buffer.data,
641+
url);
642+
free(url);
636643
/* If we have an exact match, exit. Fixes \h SELECT */
637644
if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
638645
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy