mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
Fix parsing opts from config file with leading and trailing space.
This commit is contained in:
@@ -279,7 +279,7 @@ _parse_config_files() {
|
|||||||
|
|
||||||
echo "$config_opt" | grep '^[ ]*[^#]' >/dev/null 2>&1 || continue
|
echo "$config_opt" | grep '^[ ]*[^#]' >/dev/null 2>&1 || continue
|
||||||
|
|
||||||
config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
config_opt="$(echo "$config_opt" | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
||||||
|
|
||||||
[ "$config_opt" = "" ] && continue
|
[ "$config_opt" = "" ] && continue
|
||||||
|
|
||||||
|
@@ -325,7 +325,7 @@ _parse_config_files() {
|
|||||||
|
|
||||||
# Strip leading and trailing spaces, and spaces around the first =,
|
# Strip leading and trailing spaces, and spaces around the first =,
|
||||||
# and end-of-line # comments.
|
# and end-of-line # comments.
|
||||||
config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
config_opt="$(echo "$config_opt" | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
||||||
|
|
||||||
# Skip blank lines.
|
# Skip blank lines.
|
||||||
[ "$config_opt" = "" ] && continue
|
[ "$config_opt" = "" ] && continue
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
TESTS=73
|
TESTS=78
|
||||||
|
|
||||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||||
TOOL="pt-stalk"
|
TOOL="pt-stalk"
|
||||||
@@ -166,6 +166,15 @@ is "$OPT_INT_OPT" "100" "Two --config int option"
|
|||||||
is "$ARGV" "" "Two --config ARGV"
|
is "$ARGV" "" "Two --config ARGV"
|
||||||
is "$EXT_ARGV" "--host=127.1 --user=daniel" "Two--config External ARGV"
|
is "$EXT_ARGV" "--host=127.1 --user=daniel" "Two--config External ARGV"
|
||||||
|
|
||||||
|
# Spaces before and after the option[=value] lines.
|
||||||
|
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --config $T_LIB_DIR/samples/bash/config004.conf
|
||||||
|
|
||||||
|
is "$OPT_STRING_OPT" "foo" "Default string option (spacey)"
|
||||||
|
is "$OPT_TYPELESS_OPTION" "yes" "Default typeless option (spacey)"
|
||||||
|
is "$OPT_INT_OPT" "123" "Default int option (spacey)"
|
||||||
|
is "$ARGV" "" "ARGV (spacey)"
|
||||||
|
is "$EXT_ARGV" "" "External ARGV (spacey)"
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Option values with spaces.
|
# Option values with spaces.
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
3
t/lib/samples/bash/config004.conf
Normal file
3
t/lib/samples/bash/config004.conf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
typeless-option
|
||||||
|
int-opt=123
|
||||||
|
string-opt=foo
|
Reference in New Issue
Block a user