From: Stefano Lattarini Date: Sat, 14 Jan 2012 18:04:32 +0000 (+0100) Subject: getopt: fix diagnostic for missing mandatory option argument X-Git-Tag: v2.68b~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bc3e85e91927fd7fa048a6a53d01abcf9978e6a;p=thirdparty%2Fautoconf.git 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. --- diff --git a/ChangeLog b/ChangeLog index 69df4058..c5ccc043 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-01-14 Stefano Lattarini + + 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 doc: mention Bash 2.03 bug with backslash-newline diff --git a/lib/Autom4te/General.pm b/lib/Autom4te/General.pm index f4af4c6d..5b48005a 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, '-'