Skip to content

Commit

Permalink
Withdraw part of commit 5d9947f,
Browse files Browse the repository at this point in the history
which tries to implement more GNU getopt_long campatibility.
GNU getopt_long() does not accept the (optional) argument to be
passed to the option without = sign.
However, we do, since not doing so breaks existing scripts.
  • Loading branch information
sciurius committed Feb 22, 2017
1 parent d0e8215 commit 258074d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
28 changes: 20 additions & 8 deletions lib/Getopt/Long.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
# Author : Johan Vromans
# Created On : Tue Sep 11 15:00:12 1990
# Last Modified By: Johan Vromans
# Last Modified On: Tue Feb 14 13:55:26 2017
# Update Count : 1702
# Last Modified On: Wed Feb 22 12:09:29 2017
# Update Count : 1714
# Status : Released

################ Module Preamble ################

package Getopt::Long;

use 5.004;

use strict;
use warnings;

package Getopt::Long;

use vars qw($VERSION);
$VERSION = 2.49;
Expand Down Expand Up @@ -1111,9 +1112,17 @@ sub FindOption ($$$$$) {

# Check if there is an option argument available.
if ( $gnu_compat ) {
my $optargtype = 0; # 0 = none, 1 = empty, 2 = nonempty
$optargtype = ( !defined($optarg) ? 0 : ( (length($optarg) == 0) ? 1 : 2 ) );
return (1, $opt, $ctl, defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : undef)
my $optargtype = 0; # none, 1 = empty, 2 = nonempty, 3 = aux
if ( defined($optarg) ) {
$optargtype = (length($optarg) == 0) ? 1 : 2;
}
elsif ( defined $rest || @$argv > 0 ) {
# GNU getopt_long() does not accept the (optional)
# argument to be passed to the option without = sign.
# We do, since not doing so breaks existing scripts.
$optargtype = 3;
}
return (1, $opt, $ctl, $ctl->[CTL_DEFAULT])
if (($optargtype == 0) && !$mand);
return (1, $opt, $ctl, $type eq 's' ? '' : 0)
if $optargtype == 1; # --foo= -> return nothing
Expand Down Expand Up @@ -2323,11 +2332,14 @@ do. Without C<gnu_compat>, C<--opt=> gives an error. With C<gnu_compat>,
C<--opt=> will give option C<opt> and empty value.
This is the way GNU getopt_long() does it.
Note that C<--opt value> is still accepted, even though GNU
getopt_long() doesn't.
=item gnu_getopt
This is a short way of setting C<gnu_compat> C<bundling> C<permute>
C<no_getopt_compat>. With C<gnu_getopt>, command line handling should be
fully compatible with GNU getopt_long().
reasonably compatible with GNU getopt_long().
=item require_order
Expand Down
10 changes: 7 additions & 3 deletions regtest/driver1.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Author : Johan Vromans
# Created On : Mon Aug 6 11:53:07 2001
# Last Modified By: Johan Vromans
# Last Modified On: Thu Feb 19 09:24:05 2015
# Update Count : 454
# Last Modified On: Wed Feb 22 10:21:20 2017
# Update Count : 459
# Status : Unknown, Use with caution!

package MyTest; # not main
Expand All @@ -31,6 +31,7 @@ package MyTest; # not main

my $only; # run only one test set
my $only_style; # in this style
my $quick; # quick(er) testing

# Development options (not shown with -help).
my $debug = 0; # debugging
Expand All @@ -49,6 +50,7 @@ package MyTest; # not main
}
$only = -1;
}
$only_style = 0 if $quick;

################ Presets ################

Expand Down Expand Up @@ -686,6 +688,7 @@ sub app_options {
'trace' => \$trace,
'line=s' => \$line,
'fatal' => \$fatal,
'quick' => \$quick,
'help|?' => \$help,
'debug' => \$debug,
) or $help )
Expand All @@ -705,7 +708,8 @@ sub app_usage {
print STDERR <<EndOfUsage;
Usage: $0 [options] [file ...] [test[\@variant]]
-fatal stop after first error
-line NN[\@variant] only one test after this line
-line NN[\@variant] only the test at this line, with debug
-quick quick, just one variant
-help this message
-ident show identification
-verbose verbose information
Expand Down
26 changes: 20 additions & 6 deletions regtest/test.data
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Author : Johan Vromans
# Created On : Fri Aug 24 11:23:46 2001
# Last Modified By: Johan Vromans
# Last Modified On: Tue Feb 14 13:55:20 2017
# Update Count : 555
# Last Modified On: Wed Feb 22 12:06:19 2017
# Update Count : 565
# Status : In progress

################ No args ################
Expand Down Expand Up @@ -2213,7 +2213,8 @@ A: --v1= xxx
T: Null required arguments
P: v1:s
A: --v1 "" xxx
@ARGV "" xxx
$opt_v1 ""
@ARGV xxx

O:

Expand Down Expand Up @@ -2332,10 +2333,11 @@ A: --foo=bar
T: #39052: gnu_getopt option not 100% identical to GNU getopt
# If the option has an optional argument, it must be written directly
# after the long option name, separated by '=', if present".
# THIS BREAKS SCRIPTS. WITHDRAWN in 2.50.
P: foo:s \\$v1
O: gnu_compat
A: --foo bar
@ARGV bar
$v1 bar

T: #39052: gnu_getopt option not 100% identical to GNU getopt
# Seems to break single character options with optional arguments. For
Expand All @@ -2350,11 +2352,13 @@ A: -fx y
$v1 x
@ARGV y

# THIS BREAKS SCRIPTS. WITHDRAWN in 2.50.
T: #39052: gnu_getopt option not 100% identical to GNU getopt
P: f:s \\$v1
O: gnu_compat
A: -f x y
@ARGV x y
$v1 x
@ARGV y

T: #39052: gnu_getopt option not 100% identical to GNU getopt
P: f=s \\$v1
Expand All @@ -2377,11 +2381,13 @@ A: --foo=x y
$v1 x
@ARGV y

# THIS BREAKS SCRIPTS. WITHDRAWN in 2.50.
T: #39052: gnu_getopt option not 100% identical to GNU getopt
P: foo:s \\$v1
O: gnu_compat
A: --foo x y
@ARGV x y
$v1 x
@ARGV y

T: #39052: gnu_getopt option not 100% identical to GNU getopt
P: foo=s \\$v1
Expand Down Expand Up @@ -2413,3 +2419,11 @@ O: bundling ignore_case
A: --pid
$v1 1

# Regression in 2.48
T: #120300: optional option value broken with gnu_compat
P: a:s \\$v1 b \\$v2
O: gnu_compat
A: -a avalue -b extra1 extra2
@ARGV extra1 extra2
$v1 avalue
$v2 1

0 comments on commit 258074d

Please sign in to comment.