Minor improvements for reformat_dat_file.pl.
Use Getopt::Long in preference to hand-rolled option parsing code. Also, remove "-I .../backend/catalog" switch from the Makefile invocations. That's been unnecessary for some time, and leaving it there gives the false impression it's needed in manual invocations. John Naylor (extracted from a larger but more controversial patch) Discussion: https://postgr.es/m/CACPNZCsHdcQN2jQ1=ptbi1Co2Nj3aHgRCUMk62=ThgWNabPY+Q@mail.gmail.com
This commit is contained in:
parent
e1e0e8d58c
commit
27aaf6eff4
|
@ -13,19 +13,16 @@ subdir = src/include/catalog
|
|||
top_builddir = ../../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
|
||||
# location of Catalog.pm
|
||||
catalogdir = $(top_srcdir)/src/backend/catalog
|
||||
|
||||
# 'make reformat-dat-files' is a convenience target for rewriting the
|
||||
# catalog data files in our standard format. This includes collapsing
|
||||
# out any entries that are redundant with a BKI_DEFAULT annotation.
|
||||
reformat-dat-files:
|
||||
$(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat
|
||||
$(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat
|
||||
|
||||
# 'make expand-dat-files' is a convenience target for expanding out all
|
||||
# default values in the catalog data files. This should be run before
|
||||
# altering or removing any BKI_DEFAULT annotation.
|
||||
expand-dat-files:
|
||||
$(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat --full-tuples
|
||||
$(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat --full-tuples
|
||||
|
||||
.PHONY: reformat-dat-files expand-dat-files
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use FindBin;
|
||||
use Getopt::Long;
|
||||
|
||||
# If you copy this script to somewhere other than src/include/catalog,
|
||||
# you'll need to modify this "use lib" or provide a suitable -I switch.
|
||||
use FindBin;
|
||||
use lib "$FindBin::RealBin/../../backend/catalog/";
|
||||
use Catalog;
|
||||
|
||||
|
@ -34,35 +36,16 @@ use Catalog;
|
|||
my @METADATA =
|
||||
('oid', 'oid_symbol', 'array_type_oid', 'descr', 'autogenerated');
|
||||
|
||||
my @input_files;
|
||||
# Process command line switches.
|
||||
my $output_path = '';
|
||||
my $full_tuples = 0;
|
||||
|
||||
# Process command line switches.
|
||||
while (@ARGV)
|
||||
{
|
||||
my $arg = shift @ARGV;
|
||||
if ($arg !~ /^-/)
|
||||
{
|
||||
push @input_files, $arg;
|
||||
}
|
||||
elsif ($arg =~ /^-o/)
|
||||
{
|
||||
$output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
|
||||
}
|
||||
elsif ($arg eq '--full-tuples')
|
||||
{
|
||||
$full_tuples = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage();
|
||||
}
|
||||
}
|
||||
GetOptions(
|
||||
'output=s' => \$output_path,
|
||||
'full-tuples' => \$full_tuples) || usage();
|
||||
|
||||
# Sanity check arguments.
|
||||
die "No input files.\n"
|
||||
if !@input_files;
|
||||
die "No input files.\n" unless @ARGV;
|
||||
|
||||
# Make sure output_path ends in a slash.
|
||||
if ($output_path ne '' && substr($output_path, -1) ne '/')
|
||||
|
@ -76,7 +59,7 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
|
|||
my %catalogs;
|
||||
my %catalog_data;
|
||||
my @catnames;
|
||||
foreach my $datfile (@input_files)
|
||||
foreach my $datfile (@ARGV)
|
||||
{
|
||||
$datfile =~ /(.+)\.dat$/
|
||||
or die "Input files need to be data (.dat) files.\n";
|
||||
|
@ -130,7 +113,7 @@ foreach my $catname (@catnames)
|
|||
if !(grep { $_ eq $attname } @METADATA);
|
||||
}
|
||||
|
||||
# Overwrite .dat files in place, since they are under version control.
|
||||
# Write output files to specified directory.
|
||||
my $datfile = "$output_path$catname.dat";
|
||||
open my $dat, '>', $datfile
|
||||
or die "can't open $datfile: $!";
|
||||
|
@ -318,10 +301,12 @@ sub usage
|
|||
Usage: reformat_dat_file.pl [options] datafile...
|
||||
|
||||
Options:
|
||||
-o PATH write output files to PATH instead of current directory
|
||||
--output PATH output directory (default '.')
|
||||
--full-tuples write out full tuples, including default values
|
||||
|
||||
Expects a list of .dat files as arguments.
|
||||
Non-option arguments are the names of input .dat files.
|
||||
Updated files are written to the output directory,
|
||||
possibly overwriting the input files.
|
||||
|
||||
EOM
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue