merged not-all-scripts-recognize-no-version-check-1361293

This commit is contained in:
Frank Cizmich
2014-11-06 19:09:03 -02:00
17 changed files with 141 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1132,6 +1132,16 @@ sub _read_config_file {
$parse = 0;
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
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
) {

View File

@@ -347,6 +347,9 @@ _parse_config_files() {
# Skip blank lines.
[ "$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 --,
# but command line options are, so one or the other has
# 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'
);
# #############################################################################
# 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`);
# #############################################################################