[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] getopt: fix diagnostic for missing mandatory option argument
From: |
Stefano Lattarini |
Subject: |
[PATCH] getopt: fix diagnostic for missing mandatory option argument |
Date: |
Sat, 14 Jan 2012 19:06:21 +0100 |
Before this change, an incorrect command line usage:
"autom4te --output"
triggered broken diagnostic like:
"autom4te: unrecognized option `--output'"
instead of the expected and correct:
"autom4te: option `--output' requires an argument"
* lib/Autom4te/General.pm (getopt): Give correct diagnostic in
case of usage errors due to missing arguments for options for
which they are mandatory. Code basically copied from automake's
'parse_arguments' private subroutine.
---
ChangeLog | 14 ++++++++++++++
lib/Autom4te/General.pm | 31 +++++++++++++++++++++++++++----
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 69df405..c5ccc04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-01-14 Stefano Lattarini <address@hidden>
+
+ getopt: fix diagnostic for missing mandatory option argument
+ Before this change, an incorrect command line usage:
+ "autom4te --output"
+ triggered broken diagnostic like:
+ "autom4te: unrecognized option `--output'"
+ instead of the expected and correct:
+ "autom4te: option `--output' requires an argument"
+ * lib/Autom4te/General.pm (getopt): Give correct diagnostic in
+ case of usage errors due to missing arguments for options for
+ which they are mandatory. Code basically copied from automake's
+ 'parse_arguments' private subroutine.
+
2012-01-05 Paul Eggert <address@hidden>
doc: mention Bash 2.03 bug with backslash-newline
diff --git a/lib/Autom4te/General.pm b/lib/Autom4te/General.pm
index f4af4c6..5b48005 100644
--- a/lib/Autom4te/General.pm
+++ b/lib/Autom4te/General.pm
@@ -267,11 +267,34 @@ sub getopt (%)
GetOptions (%option)
or exit 1;
- foreach (grep { /^-./ } @ARGV)
+ # FIXME: Lot of code duplication with automake here. It would probably
+ # be best to generalize our getopt() func and rip it out in a new module
+ # from which automake can sync.
+ if ($ARGV[0] =~ /^-./)
{
- print STDERR "$0: unrecognized option `$_'\n";
- print STDERR "Try `$0 --help' for more information.\n";
- exit (1);
+ my %argopts;
+ for my $k (keys %option)
+ {
+ if ($k =~ /(.*)=s$/)
+ {
+ map { $argopts{(length ($_) == 1)
+ ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
+ }
+ }
+ if ($ARGV[0] eq '--')
+ {
+ shift @ARGV;
+ }
+ elsif (exists $argopts{$ARGV[0]})
+ {
+ fatal ("option `$ARGV[0]' requires an argument\n"
+ . "Try `$0 --help' for more information.");
+ }
+ else
+ {
+ fatal ("unrecognized option `$ARGV[0]'.\n"
+ . "Try `$0 --help' for more information.");
+ }
}
push @ARGV, '-'
--
1.7.7.3
- [PATCH] getopt: fix diagnostic for missing mandatory option argument,
Stefano Lattarini <=