many scripts failed when reading no-version-check from global config file - 1361293

This commit is contained in:
Frank Cizmich
2014-10-06 19:04:49 -02:00
parent 4ba15b4887
commit dc4c506483
17 changed files with 141 additions and 27 deletions

View File

@@ -901,6 +901,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -902,6 +902,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -903,6 +903,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -86,9 +86,10 @@ usage() {
usage_or_errors() { usage_or_errors() {
local file="$1" local file="$1"
local version=""
if [ "$OPT_VERSION" ]; then if [ "$OPT_VERSION" ]; then
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
echo "$version" echo "$version"
return 1 return 1
fi fi
@@ -310,6 +311,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -251,34 +251,38 @@ parse_options() {
_parse_pod() { _parse_pod() {
local file="$1" local file="$1"
cat "$file" | PO_DIR="$PO_DIR" perl -ne ' PO_FILE="$file" PO_DIR="$PO_DIR" perl -e '
BEGIN { $/ = ""; } $/ = "";
next unless $_ =~ m/^=head1 OPTIONS/; my $file = $ENV{PO_FILE};
while ( defined(my $para = <>) ) { open my $fh, "<", $file or die "Cannot open $file: $!";
last if $para =~ m/^=head1/; while ( defined(my $para = <$fh>) ) {
chomp; next unless $para =~ m/^=head1 OPTIONS/;
if ( $para =~ m/^=item --(\S+)/ ) { while ( defined(my $para = <$fh>) ) {
my $opt = $1; last if $para =~ m/^=head1/;
my $file = "$ENV{PO_DIR}/$opt";
open my $opt_fh, ">", $file or die "Cannot open $file: $!";
print $opt_fh "long:$opt\n";
$para = <>;
chomp; chomp;
if ( $para =~ m/^[a-z ]+:/ ) { if ( $para =~ m/^=item --(\S+)/ ) {
map { my $opt = $1;
chomp; my $file = "$ENV{PO_DIR}/$opt";
my ($attrib, $val) = split(/: /, $_); open my $opt_fh, ">", $file or die "Cannot open $file: $!";
print $opt_fh "$attrib:$val\n"; print $opt_fh "long:$opt\n";
} split(/; /, $para); $para = <$fh>;
$para = <>;
chomp; chomp;
if ( $para =~ m/^[a-z ]+:/ ) {
map {
chomp;
my ($attrib, $val) = split(/: /, $_);
print $opt_fh "$attrib:$val\n";
} split(/; /, $para);
$para = <$fh>;
chomp;
}
my ($desc) = $para =~ m/^([^?.]+)/;
print $opt_fh "desc:$desc.\n";
close $opt_fh;
} }
my ($desc) = $para =~ m/^([^?.]+)/;
print $opt_fh "desc:$desc.\n";
close $opt_fh;
} }
last;
} }
last;
' '
} }
@@ -348,6 +352,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -313,6 +313,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -129,9 +129,10 @@ usage() {
usage_or_errors() { usage_or_errors() {
local file="$1" local file="$1"
local version=""
if [ "$OPT_VERSION" ]; then if [ "$OPT_VERSION" ]; then
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
echo "$version" echo "$version"
return 1 return 1
fi fi
@@ -353,6 +354,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -903,6 +903,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -127,9 +127,10 @@ usage() {
usage_or_errors() { usage_or_errors() {
local file="$1" local file="$1"
local version=""
if [ "$OPT_VERSION" ]; then if [ "$OPT_VERSION" ]; then
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
echo "$version" echo "$version"
return 1 return 1
fi fi
@@ -351,6 +352,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -911,6 +911,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -140,9 +140,10 @@ usage() {
usage_or_errors() { usage_or_errors() {
local file="$1" local file="$1"
local version=""
if [ "$OPT_VERSION" ]; then if [ "$OPT_VERSION" ]; then
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
echo "$version" echo "$version"
return 1 return 1
fi fi
@@ -364,6 +365,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -320,6 +320,8 @@ _parse_config_files() {
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi

View File

@@ -1340,6 +1340,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -1577,6 +1577,14 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -1132,6 +1132,16 @@ sub _read_config_file {
$parse = 0; $parse = 0;
next LINE; next LINE;
} }
# Silently ignore option [no]-version-check if it is unsupported and it comes from a config file
# TODO: Ideally , this should be generalized for all unsupported options that come from global files
if ( $parse
&& !$self->has('version-check')
&& $line =~ /version-check/
) {
next LINE;
}
if ( $parse if ( $parse
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) { ) {

View File

@@ -347,6 +347,9 @@ _parse_config_files() {
# Skip blank lines. # Skip blank lines.
[ "$config_opt" = "" ] && continue [ "$config_opt" = "" ] && continue
# Skip global option [no]version-check which don't apply
echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
# Options in a config file are not prefixed with --, # Options in a config file are not prefixed with --,
# but command line options are, so one or the other has # but command line options are, so one or the other has
# to add or remove the -- prefix. We add it for config # to add or remove the -- prefix. We add it for config

View File

@@ -2141,6 +2141,29 @@ is (
'prompt_no_echo outputs prompt to STDERR' 'prompt_no_echo outputs prompt to STDERR'
); );
# #############################################################################
# Issue 1361293: Global config file with no-version-check option makes tools
# that don't recognize the option fail.
# #############################################################################
diag(`echo "no-version-check" > ~/.OptionParser.t.conf`);
$o = new OptionParser(
description => 'OptionParser.t parses command line options.',
usage => "$PROGRAM_NAME <options>"
);
$o->get_specs("$trunk/bin/pt-slave-find"), # doesn't have version-check option
$output = output(
sub {
$o->get_opts();
},
stderr=>1
);
unlike(
$output,
qr/Unknown option: no-version-check/,
'no-version-check ignored if unsupported and in config file. issue 1361293'
);
diag(`rm -rf ~/.OptionParser.t.conf`);
# ############################################################################# # #############################################################################