Use TRUE/FALSE for typeless option values in --help. Update parse_options.sh lib in Bash tools.

This commit is contained in:
Daniel Nichter
2012-07-21 11:40:39 -06:00
parent 9723a297f6
commit e1b39b3d5f
6 changed files with 51 additions and 1 deletions

View File

@@ -122,6 +122,13 @@ usage_or_errors() {
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done

View File

@@ -124,6 +124,13 @@ usage_or_errors() {
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done

View File

@@ -124,6 +124,13 @@ usage_or_errors() {
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done

View File

@@ -131,6 +131,13 @@ usage_or_errors() {
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done

View File

@@ -121,6 +121,15 @@ usage_or_errors() {
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
# Typeless option, like --version, so it's given/TRUE
# or not given/FALSE.
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
plan 78
plan 80
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
TOOL="pt-stalk"
@@ -121,6 +121,19 @@ cmd_ok \
"grep -q 'Exit if the disk is less than this %full.' $TMPFILE" \
"Don't interpolate --help descriptions"
# TRUE/FALSE for typeless options, like the Perl tools.
# https://bugs.launchpad.net/percona-toolkit/+bug/954990
parse_options "$BIN_DIR/pt-stalk" --help
usage_or_errors "$BIN_DIR/pt-stalk" >$TMPFILE 2>&1
cmd_ok \
"grep -q '\-\-stalk[ ][ ]*TRUE' $TMPFILE" \
"TRUE for specified option in --help"
cmd_ok \
"grep -q '\-\-version[ ][ ]*FALSE' $TMPFILE" \
"FALSE for non-specified option in --help"
# ###########################################################################
# Config files.
# ###########################################################################