Use new pretty --help.

This commit is contained in:
Daniel Nichter
2012-01-26 12:59:48 -07:00
parent 05ac0be136
commit 6b017da6fe
3 changed files with 61 additions and 13 deletions

View File

@@ -85,12 +85,34 @@ usage_or_errors() {
echo echo
echo "Command line options:" echo "Command line options:"
echo echo
for opt in $(ls "$PO_DIR"); do perl -e '
local desc=$(cat $TMPDIR/po/$opt | grep '^desc:' | sed -e 's/^desc://') use strict;
echo "--$opt" use warnings FATAL => qw(all);
echo " $desc" my $lcol = 20; # Allow this much space for option names.
my $rcol = 80 - $lcol; # The terminal is assumed to be 80 chars wide.
my $name;
while ( <> ) {
my $line = $_;
chomp $line;
if ( $line =~ s/^long:/ --/ ) {
$name = $line;
}
elsif ( $line =~ s/^desc:// ) {
$line =~ s/ +$//mg;
my @lines = grep { $_ }
$line =~ m/(.{0,$rcol})(?:\s+|\Z)/g;
if ( length($name) >= $lcol ) {
print $name, "\n", (q{ } x $lcol);
}
else {
printf "%-${lcol}s", $name;
}
print join("\n" . (q{ } x $lcol), @lines);
print "\n";
}
}
' "$PO_DIR"/*
echo echo
done
echo "Options and values after processing arguments:" echo "Options and values after processing arguments:"
echo echo
for opt in $(ls "$PO_DIR"); do for opt in $(ls "$PO_DIR"); do

View File

@@ -91,12 +91,34 @@ usage_or_errors() {
echo echo
echo "Command line options:" echo "Command line options:"
echo echo
for opt in $(ls "$PO_DIR"); do perl -e '
local desc=$(cat $TMPDIR/po/$opt | grep '^desc:' | sed -e 's/^desc://') use strict;
echo "--$opt" use warnings FATAL => qw(all);
echo " $desc" my $lcol = 20; # Allow this much space for option names.
my $rcol = 80 - $lcol; # The terminal is assumed to be 80 chars wide.
my $name;
while ( <> ) {
my $line = $_;
chomp $line;
if ( $line =~ s/^long:/ --/ ) {
$name = $line;
}
elsif ( $line =~ s/^desc:// ) {
$line =~ s/ +$//mg;
my @lines = grep { $_ }
$line =~ m/(.{0,$rcol})(?:\s+|\Z)/g;
if ( length($name) >= $lcol ) {
print $name, "\n", (q{ } x $lcol);
}
else {
printf "%-${lcol}s", $name;
}
print join("\n" . (q{ } x $lcol), @lines);
print "\n";
}
}
' "$PO_DIR"/*
echo echo
done
echo "Options and values after processing arguments:" echo "Options and values after processing arguments:"
echo echo
for opt in $(ls "$PO_DIR"); do for opt in $(ls "$PO_DIR"); do

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
TESTS=72 TESTS=73
TMPFILE="$TEST_TMPDIR/parse-opts-output" TMPFILE="$TEST_TMPDIR/parse-opts-output"
TOOL="pt-stalk" TOOL="pt-stalk"
@@ -105,6 +105,10 @@ 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"
cmd_ok \
"grep -q ' --string-opt2[ ]*String option with a default.' $TMPFILE" \
"Command line options"
cmd_ok \ cmd_ok \
"grep -q '\-\-string-opt[ ]*(No value)' $TMPFILE" \ "grep -q '\-\-string-opt[ ]*(No value)' $TMPFILE" \
"Options and values after processing arguments" "Options and values after processing arguments"