Skip to content

Commit bfea331

Browse files
committed
Rework option set of vacuumlo
Like oid2name, vacuumlo has been lacking consistency with other utilities for its options: - Connection options gain long aliases. - Document environment variables which could be used: PGHOST, PGPORT and PGUSER. Documentation and code is reordered to be more consistent. A basic set of TAP tests has been added while on it. Author: Tatsuro Yamada Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/c7e7f25c-1747-cd0f-9335-390bc97b2db5@lab.ntt.co.jp
1 parent 1aaf532 commit bfea331

File tree

5 files changed

+98
-37
lines changed

5 files changed

+98
-37
lines changed

contrib/vacuumlo/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/vacuumlo
2+
3+
/tmp_check/

contrib/vacuumlo/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ top_builddir = ../..
1919
include $(top_builddir)/src/Makefile.global
2020
include $(top_srcdir)/contrib/contrib-global.mk
2121
endif
22+
23+
check:
24+
$(prove_check)
25+
26+
installcheck:
27+
$(prove_installcheck)

contrib/vacuumlo/t/001_basic.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use strict;
2+
use warnings;
3+
4+
use TestLib;
5+
use Test::More tests => 8;
6+
7+
program_help_ok('vacuumlo');
8+
program_version_ok('vacuumlo');
9+
program_options_handling_ok('vacuumlo');

contrib/vacuumlo/vacuumlo.c

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "fe_utils/connect.h"
2727
#include "libpq-fe.h"
2828
#include "pg_getopt.h"
29+
#include "getopt_long.h"
2930

3031
#define BUFSIZE 1024
3132

@@ -434,17 +435,17 @@ usage(const char *progname)
434435
printf("%s removes unreferenced large objects from databases.\n\n", progname);
435436
printf("Usage:\n %s [OPTION]... DBNAME...\n\n", progname);
436437
printf("Options:\n");
437-
printf(" -l LIMIT commit after removing each LIMIT large objects\n");
438-
printf(" -n don't remove large objects, just show what would be done\n");
439-
printf(" -v write a lot of progress messages\n");
440-
printf(" -V, --version output version information, then exit\n");
441-
printf(" -?, --help show this help, then exit\n");
438+
printf(" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
439+
printf(" -n, --dry-run don't remove large objects, just show what would be done\n");
440+
printf(" -v, --verbose write a lot of progress messages\n");
441+
printf(" -V, --version output version information, then exit\n");
442+
printf(" -?, --help show this help, then exit\n");
442443
printf("\nConnection options:\n");
443-
printf(" -h HOSTNAME database server host or socket directory\n");
444-
printf(" -p PORT database server port\n");
445-
printf(" -U USERNAME user name to connect as\n");
446-
printf(" -w never prompt for password\n");
447-
printf(" -W force password prompt\n");
444+
printf(" -h, --host=HOSTNAME database server host or socket directory\n");
445+
printf(" -p, --port=PORT database server port\n");
446+
printf(" -U, --username=USERNAME user name to connect as\n");
447+
printf(" -w, --no-password never prompt for password\n");
448+
printf(" -W, --password force password prompt\n");
448449
printf("\n");
449450
printf("Report bugs to <pgsql-bugs@postgresql.org>.\n");
450451
}
@@ -453,11 +454,26 @@ usage(const char *progname)
453454
int
454455
main(int argc, char **argv)
455456
{
457+
static struct option long_options[] = {
458+
{"host", required_argument, NULL, 'h'},
459+
{"limit", required_argument, NULL, 'l'},
460+
{"dry-run", no_argument, NULL, 'n'},
461+
{"port", required_argument, NULL, 'p'},
462+
{"username", required_argument, NULL, 'U'},
463+
{"verbose", no_argument, NULL, 'v'},
464+
{"version", no_argument, NULL, 'V'},
465+
{"no-password", no_argument, NULL, 'w'},
466+
{"password", no_argument, NULL, 'W'},
467+
{"help", no_argument, NULL, '?'},
468+
{NULL, 0, NULL, 0}
469+
};
470+
456471
int rc = 0;
457472
struct _param param;
458473
int c;
459474
int port;
460475
const char *progname;
476+
int optindex;
461477

462478
progname = get_progname(argv[0]);
463479

@@ -486,25 +502,15 @@ main(int argc, char **argv)
486502
}
487503
}
488504

489-
while (1)
505+
while ((c = getopt_long(argc, argv, "h:l:np:U:vwW", long_options, &optindex)) != -1)
490506
{
491-
c = getopt(argc, argv, "h:l:U:p:vnwW");
492-
if (c == -1)
493-
break;
494-
495507
switch (c)
496508
{
497509
case '?':
498510
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
499511
exit(1);
500-
case ':':
501-
exit(1);
502-
case 'v':
503-
param.verbose = 1;
504-
break;
505-
case 'n':
506-
param.dry_run = 1;
507-
param.verbose = 1;
512+
case 'h':
513+
param.pg_host = pg_strdup(optarg);
508514
break;
509515
case 'l':
510516
param.transaction_limit = strtol(optarg, NULL, 10);
@@ -516,14 +522,9 @@ main(int argc, char **argv)
516522
exit(1);
517523
}
518524
break;
519-
case 'U':
520-
param.pg_user = pg_strdup(optarg);
521-
break;
522-
case 'w':
523-
param.pg_prompt = TRI_NO;
524-
break;
525-
case 'W':
526-
param.pg_prompt = TRI_YES;
525+
case 'n':
526+
param.dry_run = 1;
527+
param.verbose = 1;
527528
break;
528529
case 'p':
529530
port = strtol(optarg, NULL, 10);
@@ -534,9 +535,21 @@ main(int argc, char **argv)
534535
}
535536
param.pg_port = pg_strdup(optarg);
536537
break;
537-
case 'h':
538-
param.pg_host = pg_strdup(optarg);
538+
case 'U':
539+
param.pg_user = pg_strdup(optarg);
539540
break;
541+
case 'v':
542+
param.verbose = 1;
543+
break;
544+
case 'w':
545+
param.pg_prompt = TRI_NO;
546+
break;
547+
case 'W':
548+
param.pg_prompt = TRI_YES;
549+
break;
550+
default:
551+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
552+
exit(1);
540553
}
541554
}
542555

doc/src/sgml/vacuumlo.sgml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555

5656
<variablelist>
5757
<varlistentry>
58-
<term><option>-l</option> <replaceable>limit</replaceable></term>
58+
<term><option>-l <replaceable class="parameter">limit</replaceable></option></term>
59+
<term><option>--limit=<replaceable class="parameter">limit</replaceable></option></term>
5960
<listitem>
6061
<para>
6162
Remove no more than <replaceable>limit</replaceable> large objects per
@@ -69,13 +70,15 @@
6970

7071
<varlistentry>
7172
<term><option>-n</option></term>
73+
<term><option>--dry-run</option></term>
7274
<listitem>
7375
<para>Don't remove anything, just show what would be done.</para>
7476
</listitem>
7577
</varlistentry>
7678

7779
<varlistentry>
7880
<term><option>-v</option></term>
81+
<term><option>--verbose</option></term>
7982
<listitem>
8083
<para>Write a lot of progress messages.</para>
8184
</listitem>
@@ -110,21 +113,24 @@
110113

111114
<variablelist>
112115
<varlistentry>
113-
<term><option>-h</option> <replaceable>hostname</replaceable></term>
116+
<term><option>-h <replaceable class="parameter">host</replaceable></option></term>
117+
<term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
114118
<listitem>
115119
<para>Database server's host.</para>
116120
</listitem>
117121
</varlistentry>
118122

119123
<varlistentry>
120-
<term><option>-p</option> <replaceable>port</replaceable></term>
124+
<term><option>-p <replaceable>port</replaceable></option></term>
125+
<term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
121126
<listitem>
122127
<para>Database server's port.</para>
123128
</listitem>
124129
</varlistentry>
125130

126131
<varlistentry>
127-
<term><option>-U</option> <replaceable>username</replaceable></term>
132+
<term><option>-U <replaceable>username</replaceable></option></term>
133+
<term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
128134
<listitem>
129135
<para>User name to connect as.</para>
130136
</listitem>
@@ -146,6 +152,7 @@
146152

147153
<varlistentry>
148154
<term><option>-W</option></term>
155+
<term><option>--password</option></term>
149156
<listitem>
150157
<para>
151158
Force <application>vacuumlo</application> to prompt for a
@@ -167,6 +174,30 @@
167174
</para>
168175
</refsect1>
169176

177+
<refsect1>
178+
<title>Environment</title>
179+
180+
<variablelist>
181+
<varlistentry>
182+
<term><envar>PGHOST</envar></term>
183+
<term><envar>PGPORT</envar></term>
184+
<term><envar>PGUSER</envar></term>
185+
186+
<listitem>
187+
<para>
188+
Default connection parameters.
189+
</para>
190+
</listitem>
191+
</varlistentry>
192+
</variablelist>
193+
194+
<para>
195+
This utility, like most other <productname>PostgreSQL</productname> utilities,
196+
also uses the environment variables supported by <application>libpq</application>
197+
(see <xref linkend="libpq-envars"/>).
198+
</para>
199+
</refsect1>
200+
170201
<refsect1>
171202
<title>Notes</title>
172203

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