From 51b93a623559a203207360733348b5fb66c620fc Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 19 Jan 2012 12:20:33 -0700 Subject: [PATCH] Fix --help description interpolation. --- bin/pt-stalk | 6 +++--- lib/bash/parse_options.sh | 6 +++--- t/lib/bash.t | 1 + t/lib/bash/parse_options.sh | 10 +++++++++- t/lib/samples/bash/po003.sh | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 t/lib/samples/bash/po003.sh diff --git a/bin/pt-stalk b/bin/pt-stalk index 2fb45bfa..1968cb85 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -128,20 +128,20 @@ parse_options() { my $opt = $1; my $file = "$ENV{PO_DIR}/$opt"; open my $opt_fh, ">", $file or die "Cannot open $file: $!"; - printf $opt_fh "long:$opt\n"; + print $opt_fh "long:$opt\n"; $para = <>; chomp; if ( $para =~ m/^[a-z ]+:/ ) { map { chomp; my ($attrib, $val) = split(/: /, $_); - printf $opt_fh "$attrib:$val\n"; + print $opt_fh "$attrib:$val\n"; } split(/; /, $para); $para = <>; chomp; } my ($desc) = $para =~ m/^([^?.]+)/; - printf $opt_fh "desc:$desc.\n"; + print $opt_fh "desc:$desc.\n"; close $opt_fh; } } diff --git a/lib/bash/parse_options.sh b/lib/bash/parse_options.sh index 21d580d2..293d4f76 100644 --- a/lib/bash/parse_options.sh +++ b/lib/bash/parse_options.sh @@ -137,20 +137,20 @@ parse_options() { my $opt = $1; my $file = "$ENV{PO_DIR}/$opt"; open my $opt_fh, ">", $file or die "Cannot open $file: $!"; - printf $opt_fh "long:$opt\n"; + print $opt_fh "long:$opt\n"; $para = <>; chomp; if ( $para =~ m/^[a-z ]+:/ ) { map { chomp; my ($attrib, $val) = split(/: /, $_); - printf $opt_fh "$attrib:$val\n"; + print $opt_fh "$attrib:$val\n"; } split(/; /, $para); $para = <>; chomp; } my ($desc) = $para =~ m/^([^?.]+)/; - printf $opt_fh "desc:$desc.\n"; + print $opt_fh "desc:$desc.\n"; close $opt_fh; } } diff --git a/t/lib/bash.t b/t/lib/bash.t index aaf1fe28..6b6f3998 100644 --- a/t/lib/bash.t +++ b/t/lib/bash.t @@ -15,6 +15,7 @@ use PerconaTest; my ($tool) = $PROGRAM_NAME =~ m/([\w-]+)\.t$/; push @ARGV, "$trunk/t/lib/bash/*.sh" unless @ARGV; +$ENV{BIN_DIR} = "$trunk/bin"; $ENV{LIB_DIR} = "$trunk/lib/bash"; $ENV{T_LIB_DIR} = "$trunk/t/lib"; diff --git a/t/lib/bash/parse_options.sh b/t/lib/bash/parse_options.sh index 482bc46d..c65fe24c 100644 --- a/t/lib/bash/parse_options.sh +++ b/t/lib/bash/parse_options.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -TESTS=26 +TESTS=27 TMPFILE="$TEST_TMPDIR/parse-opts-output" @@ -81,6 +81,14 @@ cmd_ok \ "grep -q \"For more information, 'man pt-stalk' or 'perldoc\" $TMPFILE" \ "--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 # ############################################################################ diff --git a/t/lib/samples/bash/po003.sh b/t/lib/samples/bash/po003.sh new file mode 100644 index 00000000..a7971cdc --- /dev/null +++ b/t/lib/samples/bash/po003.sh @@ -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