|
20 | 20 | use strict;
|
21 | 21 | use warnings;
|
22 | 22 |
|
| 23 | +use FindBin; |
| 24 | +use Getopt::Long; |
| 25 | + |
23 | 26 | # If you copy this script to somewhere other than src/include/catalog,
|
24 | 27 | # you'll need to modify this "use lib" or provide a suitable -I switch.
|
25 |
| -use FindBin; |
26 | 28 | use lib "$FindBin::RealBin/../../backend/catalog/";
|
27 | 29 | use Catalog;
|
28 | 30 |
|
|
34 | 36 | my @METADATA =
|
35 | 37 | ('oid', 'oid_symbol', 'array_type_oid', 'descr', 'autogenerated');
|
36 | 38 |
|
37 |
| -my @input_files; |
| 39 | +# Process command line switches. |
38 | 40 | my $output_path = '';
|
39 | 41 | my $full_tuples = 0;
|
40 | 42 |
|
41 |
| -# Process command line switches. |
42 |
| -while (@ARGV) |
43 |
| -{ |
44 |
| - my $arg = shift @ARGV; |
45 |
| - if ($arg !~ /^-/) |
46 |
| - { |
47 |
| - push @input_files, $arg; |
48 |
| - } |
49 |
| - elsif ($arg =~ /^-o/) |
50 |
| - { |
51 |
| - $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; |
52 |
| - } |
53 |
| - elsif ($arg eq '--full-tuples') |
54 |
| - { |
55 |
| - $full_tuples = 1; |
56 |
| - } |
57 |
| - else |
58 |
| - { |
59 |
| - usage(); |
60 |
| - } |
61 |
| -} |
| 43 | +GetOptions( |
| 44 | + 'output=s' => \$output_path, |
| 45 | + 'full-tuples' => \$full_tuples) || usage(); |
62 | 46 |
|
63 | 47 | # Sanity check arguments.
|
64 |
| -die "No input files.\n" |
65 |
| - if !@input_files; |
| 48 | +die "No input files.\n" unless @ARGV; |
66 | 49 |
|
67 | 50 | # Make sure output_path ends in a slash.
|
68 | 51 | if ($output_path ne '' && substr($output_path, -1) ne '/')
|
|
76 | 59 | my %catalogs;
|
77 | 60 | my %catalog_data;
|
78 | 61 | my @catnames;
|
79 |
| -foreach my $datfile (@input_files) |
| 62 | +foreach my $datfile (@ARGV) |
80 | 63 | {
|
81 | 64 | $datfile =~ /(.+)\.dat$/
|
82 | 65 | or die "Input files need to be data (.dat) files.\n";
|
|
130 | 113 | if !(grep { $_ eq $attname } @METADATA);
|
131 | 114 | }
|
132 | 115 |
|
133 |
| - # Overwrite .dat files in place, since they are under version control. |
| 116 | + # Write output files to specified directory. |
134 | 117 | my $datfile = "$output_path$catname.dat";
|
135 | 118 | open my $dat, '>', $datfile
|
136 | 119 | or die "can't open $datfile: $!";
|
@@ -318,10 +301,12 @@ sub usage
|
318 | 301 | Usage: reformat_dat_file.pl [options] datafile...
|
319 | 302 |
|
320 | 303 | Options:
|
321 |
| - -o PATH write output files to PATH instead of current directory |
| 304 | + --output PATH output directory (default '.') |
322 | 305 | --full-tuples write out full tuples, including default values
|
323 | 306 |
|
324 |
| -Expects a list of .dat files as arguments. |
| 307 | +Non-option arguments are the names of input .dat files. |
| 308 | +Updated files are written to the output directory, |
| 309 | +possibly overwriting the input files. |
325 | 310 |
|
326 | 311 | EOM
|
327 | 312 | }
|
0 commit comments