Fix --help description interpolation.

This commit is contained in:
Daniel Nichter
2012-01-19 12:20:33 -07:00
parent ba4b4f3059
commit 51b93a6235
5 changed files with 53 additions and 7 deletions

View File

@@ -128,20 +128,20 @@ parse_options() {
my $opt = $1; my $opt = $1;
my $file = "$ENV{PO_DIR}/$opt"; my $file = "$ENV{PO_DIR}/$opt";
open my $opt_fh, ">", $file or die "Cannot open $file: $!"; open my $opt_fh, ">", $file or die "Cannot open $file: $!";
printf $opt_fh "long:$opt\n"; print $opt_fh "long:$opt\n";
$para = <>; $para = <>;
chomp; chomp;
if ( $para =~ m/^[a-z ]+:/ ) { if ( $para =~ m/^[a-z ]+:/ ) {
map { map {
chomp; chomp;
my ($attrib, $val) = split(/: /, $_); my ($attrib, $val) = split(/: /, $_);
printf $opt_fh "$attrib:$val\n"; print $opt_fh "$attrib:$val\n";
} split(/; /, $para); } split(/; /, $para);
$para = <>; $para = <>;
chomp; chomp;
} }
my ($desc) = $para =~ m/^([^?.]+)/; my ($desc) = $para =~ m/^([^?.]+)/;
printf $opt_fh "desc:$desc.\n"; print $opt_fh "desc:$desc.\n";
close $opt_fh; close $opt_fh;
} }
} }

View File

@@ -137,20 +137,20 @@ parse_options() {
my $opt = $1; my $opt = $1;
my $file = "$ENV{PO_DIR}/$opt"; my $file = "$ENV{PO_DIR}/$opt";
open my $opt_fh, ">", $file or die "Cannot open $file: $!"; open my $opt_fh, ">", $file or die "Cannot open $file: $!";
printf $opt_fh "long:$opt\n"; print $opt_fh "long:$opt\n";
$para = <>; $para = <>;
chomp; chomp;
if ( $para =~ m/^[a-z ]+:/ ) { if ( $para =~ m/^[a-z ]+:/ ) {
map { map {
chomp; chomp;
my ($attrib, $val) = split(/: /, $_); my ($attrib, $val) = split(/: /, $_);
printf $opt_fh "$attrib:$val\n"; print $opt_fh "$attrib:$val\n";
} split(/; /, $para); } split(/; /, $para);
$para = <>; $para = <>;
chomp; chomp;
} }
my ($desc) = $para =~ m/^([^?.]+)/; my ($desc) = $para =~ m/^([^?.]+)/;
printf $opt_fh "desc:$desc.\n"; print $opt_fh "desc:$desc.\n";
close $opt_fh; close $opt_fh;
} }
} }

View File

@@ -15,6 +15,7 @@ use PerconaTest;
my ($tool) = $PROGRAM_NAME =~ m/([\w-]+)\.t$/; my ($tool) = $PROGRAM_NAME =~ m/([\w-]+)\.t$/;
push @ARGV, "$trunk/t/lib/bash/*.sh" unless @ARGV; push @ARGV, "$trunk/t/lib/bash/*.sh" unless @ARGV;
$ENV{BIN_DIR} = "$trunk/bin";
$ENV{LIB_DIR} = "$trunk/lib/bash"; $ENV{LIB_DIR} = "$trunk/lib/bash";
$ENV{T_LIB_DIR} = "$trunk/t/lib"; $ENV{T_LIB_DIR} = "$trunk/t/lib";

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
TESTS=26 TESTS=27
TMPFILE="$TEST_TMPDIR/parse-opts-output" TMPFILE="$TEST_TMPDIR/parse-opts-output"
@@ -81,6 +81,14 @@ cmd_ok \
"grep -q \"For more information, 'man pt-stalk' or 'perldoc\" $TMPFILE" \ "grep -q \"For more information, 'man pt-stalk' or 'perldoc\" $TMPFILE" \
"--help" "--help"
# Don't interpolate.
parse_options "$T_LIB_DIR/samples/bash/po003.sh" --help
usage_or_errors "$T_LIB_DIR/samples/bash/po003.sh" >$TMPFILE 2>&1
cmd_ok \
"grep -q 'Exit if the disk is less than this %full.' $TMPFILE" \
"Don't interpolate --help descriptions"
# ############################################################################ # ############################################################################
# Done # Done
# ############################################################################ # ############################################################################

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
:
# ############################################################################
# Documentation
# ############################################################################
:<<'DOCUMENTATION'
=pod
=head1 NAME
pt-stalk - Wait for a condition to occur then begin collecting data.
=head1 OPTIONS
=over
=item --disk-pct-limit
type: int; default: 5
Exit if the disk is less than this %full.
=item --help
Print help.
=back
=head1 ENVIRONMENT
No env vars used.
=cut
DOCUMENTATION