summaryrefslogtreecommitdiff
path: root/installperl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-04-25 14:38:00 +0200
committerNicholas Clark <nick@ccl4.org>2013-07-13 12:01:37 +0200
commit3f7e1bf8b573541d1d93e89278657b6e6438b69a (patch)
tree700c5b352f13e1ee7d3a18c09e74f2c78dedd496 /installperl
parent4609f84fc954f9ef279e0204408c7e7f64fa58c9 (diff)
downloadperl-3f7e1bf8b573541d1d93e89278657b6e6438b69a.tar.gz
Convert installperl to use Getopt::Long.
This requires some special handling for the +v option. Fortunately, we can cheat, because we know that no other non-options are acceptable. This does change the behaviour slightly from before: * single letter options now also have long names * invalid options are now rejected * command line arguments that are not options are now rejected However, the behaviour for all valid documented invocations is unchanged. Also, add a --help option to display the usage message.
Diffstat (limited to 'installperl')
-rwxr-xr-xinstallperl43
1 files changed, 24 insertions, 19 deletions
diff --git a/installperl b/installperl
index 6b4898cdd1..9cf7d7b663 100755
--- a/installperl
+++ b/installperl
@@ -27,6 +27,8 @@ use File::Copy ();
use File::Path ();
use ExtUtils::Packlist;
use Cwd;
+# nogetopt_compat to disable treating +v as meaning -v
+use Getopt::Long qw(:config nogetopt_compat no_auto_abbrev noignorecase);
require './Porting/pod_lib.pl';
@@ -69,23 +71,26 @@ if ( $Is_VMS ) {
# defined, it's also possible to make the s/\Q$opts{destdir}\E unconditional.
$opts{destdir} = '';
-# Consider refactoring this to use Getopt::Long once Getopt::Long's planned
-# feature is implemented, to distinguish + and - options.
-while (@ARGV) {
- $opts{notify} = 1 if $ARGV[0] eq '-n';
- $opts{strip} = 1 if $ARGV[0] eq '-s';
- $versiononly = 1 if $ARGV[0] eq '-v';
- $versiononly = 0 if $ARGV[0] eq '+v';
- $opts{silent} = 1 if $ARGV[0] eq '-S';
- $opts{'skip-otherperls'} = 1 if $ARGV[0] eq '-o';
- $opts{force} = 1 if $ARGV[0] eq '-f';
- $opts{verbose} = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n';
- $opts{archname} = 1 if $ARGV[0] eq '-A';
- $opts{netware} = 1 if $ARGV[0] eq '-netware';
- $opts{nopods} = 1 if $ARGV[0] eq '-p';
- $opts{destdir} = $1 if $ARGV[0] =~ /^-?-destdir=(.*)$/;
- if ($ARGV[0] eq '-?' or $ARGV[0] =~ /^-?-h/) {
- print <<"EOT";
+{
+ my $usage = 0;
+ if (!GetOptions(\%opts, 'notify|n', 'strip|s', 'silent|S',
+ 'skip-otherperls|o', 'force|f', 'verbose|V', 'archname|A',
+ 'netware', 'nopods|p', 'destdir:s', 'help|h|?',
+ 'versiononly|v' => \$versiononly, '<>' => sub {
+ if ($_[0] eq '+v') {
+ $versiononly = 0;
+ } else {
+ # Any other unknown argument is going to be an error
+ $usage = 1;
+ }
+ },
+ )) {
+ $usage = 1;
+ }
+ $opts{verbose} ||= $opts{notify};
+
+ if ($usage || $opts{help}) {
+ print <<"EOT";
Usage $0: [switches]
-n Don't actually run any commands; just print them.
-s Run strip on installed binaries.
@@ -102,10 +107,10 @@ Usage $0: [switches]
-p Don't install the pod files. [This will break use diagnostics;]
-netware Install correctly on a Netware server.
-destdir Prefix installation directories by this string.
+ -h Display this help message.
EOT
- exit;
+ exit $usage;
}
- shift;
}
$versiononly = 1 if $Config{versiononly} && !defined $versiononly;