]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
getopt: fix diagnostic for missing mandatory option argument
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 14 Jan 2012 18:04:32 +0000 (19:04 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 14 Jan 2012 18:04:32 +0000 (19:04 +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
lib/Autom4te/General.pm

index 69df4058c701ac5cf49273548e0bacc22864fd44..c5ccc043d9de128f423609f8d2ddf9c34335ef4e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-01-14  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       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  <eggert@cs.ucla.edu>
 
        doc: mention Bash 2.03 bug with backslash-newline
index f4af4c6d786b8a559bdf18775ef812b70d7196e6..5b48005ae4d49e275d41e37cd10c7e36f514e3b0 100644 (file)
@@ -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, '-'