More parse_options tests. Make --opt yes have value "yes" instead of "1". Change ok() to cmd_ok() in test-bash-functions. Mimic Perl modulue headers in Bash libs so update-modules will work with the latter.

This commit is contained in:
Daniel Nichter
2011-10-28 11:08:59 -06:00
parent 1ec666de0e
commit f2b644ba72
7 changed files with 115 additions and 41 deletions

View File

@@ -15,14 +15,15 @@
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Begin log_warn_die lib
# log_warn_die package
# ###########################################################################
# Library: log_warn_die
# Package: log_warn_die
# log_warn_die provides standard log(), warn(), and die() subs.
set -u
# Global variables.
EXIT_STATUS=0
log() {
@@ -41,5 +42,5 @@ die() {
}
# ###########################################################################
# End log_warn_die lib
# End log_warn_die package
# ###########################################################################

View File

@@ -15,10 +15,10 @@
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Begin parse_options lib
# parse_options package
# ###########################################################################
# Library: parse_options
# Package: parse_options
# parse_options parses Perl POD options from Bash tools and creates
# global variables for each option.
@@ -36,7 +36,7 @@ declare EXT_ARGV # everything after -- (args for an external command)
# file - Program file with Perl POD which has usage and options.
#
# Required Global Variables:
# TIMDIR - Temp directory.
# TIMDIR - Temp directory set by <set_TMPDIR()>.
# TOOL - Tool's name.
#
# Optional Global Variables:
@@ -66,9 +66,9 @@ usage() {
# file - Program file with Perl POD options.
#
# Required Global Variables:
# TIMDIR - Temp directory.
# TIMDIR - Temp directory set by <set_TMPDIR()>.
#
# Declared Global Variables:
# Set Global Variables:
# This sub decalres a global var for each option by uppercasing the
# option, removing the option's leading --, changing all - to _, and
# prefixing with "OPT_". E.g. --foo-bar becomes OPT_FOO_BAR.
@@ -121,7 +121,7 @@ parse_options() {
while read spec; do
opt=$(echo $spec | cut -d',' -f1 | sed 's/-/_/g' | tr [:lower:] [:upper:])
default=$(echo $spec | cut -d',' -f4)
eval "$opt"="$default"
eval "OPT_${opt}"="$default"
done < <(cat $TMPDIR/options)
for opt; do
@@ -156,7 +156,7 @@ parse_options() {
fi
opt=$(echo $spec | cut -d',' -f1)
required_arg=$(echo $spec | cut -d',' -f3)
val=1
val="yes"
if [ -n "$required_arg" ]; then
if [ $# -eq 0 ]; then
die "--$opt requires a $required_arg argument"
@@ -166,10 +166,10 @@ parse_options() {
fi
fi
opt=$(echo $opt | sed 's/-/_/g' | tr [:lower:] [:upper:])
eval "$opt"="$val"
eval "OPT_${opt}"="$val"
done
}
# ###########################################################################
# End parse_options lib
# End parse_options package
# ###########################################################################

View File

@@ -15,17 +15,26 @@
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Begin tmpdir lib
# tmpdir package
# ###########################################################################
# Library: tmpdir
# Package: tmpdir
# tmpdir make a secure temporary directory using mktemp.
set -u
# Global variables.
TMPDIR=""
OPT_TMPDIR={OPT_TMPDIR:""}
# Sub: set_TMPDIR
# Create a secure tmpdir and set TMPDIR.
#
# Optional Global Variables:
# OPT_TMPDIR - User-specified --tmpdir (default none).
#
# Set Global Variables:
# TMPDIR - Absolute path of secure temp directory.
set_TMPDIR() {
if [ -n "$OPT_TMPDIR" ]; then
TMPDIR="$OPT_TMPDIR"
@@ -38,6 +47,14 @@ set_TMPDIR() {
fi
}
# Sub: rm_TMPDIR
# Remove the tmpdir and unset TMPDIR.
#
# Optional Global Variables:
# TMPDIR - TMPDIR set by <set_TMPDIR()>.
#
# Set Global Variables:
# TMPDIR - Set to "".
rm_TMPDIR() {
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf $TMPDIR
@@ -46,5 +63,5 @@ rm_TMPDIR() {
}
# ###########################################################################
# End tmpdir lib
# End tmpdir package
# ###########################################################################