From d216528e9952b285961d02663db13ff3f9525cf8 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 22 Sep 2021 17:55:25 -0700 Subject: [PATCH] update utility pm2pl with flags -D -o ofname --- pm2pl | 96 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/pm2pl b/pm2pl index b62a6ef1..090c66de 100755 --- a/pm2pl +++ b/pm2pl @@ -1,5 +1,6 @@ #!/usr/bin/env perl use strict; +use Getopt::Long; # This script will recombine the perltidy binary script and all of its modules # into a single, monolithic script. I use it for making a temporary "sandbox" @@ -8,12 +9,38 @@ use strict; # This is also useful for making a copy of previous versions for parallel # debugging sessions. -# usage: -# perl pm2pl +my $usage = < 1 [ for extra testing when debugging ] +EOM + +my @option_string = qw( + h + o:s + D +); + +my %Opts = (); +if ( !GetOptions( \%Opts, @option_string ) ) { + die "Programming Bug: error in setting default options"; +} + +if ( $Opts{h} ) { + print $usage; + exit 1; +} # This should work for a system with File::Spec, # and for older Windows/Unix systems without File::Spec. @@ -51,44 +78,59 @@ unless ($missing_file_spec) { my $VERSION = get_version("lib/Perl/Tidy.pm"); my $outfile = "perltidy-$VERSION.pl"; -open OUTFILE, "> $outfile" or die "can't open file '$outfile' : $!\n"; -print "Creating standalone formatter script '$outfile' ....\n "; +if ( $Opts{o} ) { $outfile = $Opts{o} } +my $fh_out; +open( $fh_out,, ">", $outfile ) or die "can't open file '$outfile' : $!\n"; +print "Creating standalone perltidy script '$outfile' ...."; # first, open the script and copy the first (hash-bang) line # (Note: forward slashes in file names here will work in Windows) -open SCRIPT, "< $script" or die "can't open script file '$script' : $!\n"; -my $hash_bang =