summaryrefslogtreecommitdiff
path: root/Debian/Debhelper/Dh_Getopt.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-12-14 22:13:32 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-12-14 22:13:32 -0500
commite90eebf73099da05ffb1d1e2be30a2eccafd153c (patch)
treecffd293f81abaa33eec275e289accec550a5f5df /Debian/Debhelper/Dh_Getopt.pm
parenta0fc3f57b576cd7c88a698330233df26ff13137f (diff)
Ignore unknown options in DH_OPTIONS. Debhelper will always ignore such options, even when unknown command-line options are converted back to an error. This allows (ab)using DH_OPTIONS to pass command-specific options. (Note that getopt will warn about such unknown options. Eliminating this warning without reimplementing much of Getopt::Long wasn't practical.)
Diffstat (limited to 'Debian/Debhelper/Dh_Getopt.pm')
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm30
1 files changed, 25 insertions, 5 deletions
diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm
index cc15ddd..950a37b 100644
--- a/Debian/Debhelper/Dh_Getopt.pm
+++ b/Debian/Debhelper/Dh_Getopt.pm
@@ -69,11 +69,11 @@ sub NonOption {
push @{$dh{ARGV}}, @_;
}
-# Parse options and set %dh values.
-sub parseopts {
+sub getoptions {
+ my $array=shift;
my %options=%{shift()} if ref $_[0];
- my $ret=GetOptions(
+ Getopt::Long::GetOptionsFromArray($array,
"v" => \$dh{VERBOSE},
"verbose" => \$dh{VERBOSE},
@@ -138,8 +138,28 @@ sub parseopts {
%options,
"<>" => \&NonOption,
- );
+ )
+}
+
+# Parse options and set %dh values.
+sub parseopts {
+ my $options=shift;
+
+ # DH_OPTIONS can contain additional options
+ # to be parsed like @ARGV, but with unknown options
+ # skipped.
+ my @ARGV_extra;
+ if (defined $ENV{DH_OPTIONS}) {
+ $ENV{DH_OPTIONS}=~s/^\s+//;
+ $ENV{DH_OPTIONS}=~s/\s+$//;
+ @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS});
+ my $ret=getoptions(\@ARGV_extra, $options);
+ if (!$ret) {
+ warning("warning: ignored unknown options in DH_OPTIONS");
+ }
+ }
+ my $ret=getoptions(\@ARGV, $options);
if (!$ret) {
warning("warning: unknown options will be a fatal error in a future debhelper release");
#error("unknown option; aborting");
@@ -195,7 +215,7 @@ sub parseopts {
# Anything left in @ARGV is options that appeared after a --
# These options are added to the U_PARAMS array, while the
# non-option values we collected replace them in @ARGV;
- push @{$dh{U_PARAMS}}, @ARGV;
+ push @{$dh{U_PARAMS}}, @ARGV, @ARGV_extra;
@ARGV=@{$dh{ARGV}} if exists $dh{ARGV};
}