mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Add and test --config to pt-stalk.
This commit is contained in:
57
bin/pt-stalk
57
bin/pt-stalk
@@ -54,12 +54,12 @@ die() {
|
||||
|
||||
set -u
|
||||
|
||||
ARGV="" # Non-option args (probably input files)
|
||||
EXT_ARGV="" # Everything after -- (args for an external command)
|
||||
HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV
|
||||
OPT_ERRS=0 # How many command line option errors
|
||||
OPT_VERSION="no" # If --version was specified
|
||||
OPT_HELP="no" # If --help was specified
|
||||
ARGV="" # Non-option args (probably input files)
|
||||
EXT_ARGV="" # Everything after -- (args for an external command)
|
||||
HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV
|
||||
OPT_ERRS=0 # How many command line option errors
|
||||
OPT_VERSION="" # If --version was specified
|
||||
OPT_HELP="" # If --help was specified
|
||||
PO_DIR="$TMPDIR/po" # Directory with program option spec files
|
||||
|
||||
usage() {
|
||||
@@ -74,13 +74,13 @@ usage() {
|
||||
usage_or_errors() {
|
||||
local file="$1"
|
||||
|
||||
if [ "$OPT_VERSION" = "yes" ]; then
|
||||
if [ "$OPT_VERSION" ]; then
|
||||
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
|
||||
echo "$version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$OPT_HELP" = "yes" ]; then
|
||||
if [ "$OPT_HELP" ]; then
|
||||
usage "$file"
|
||||
echo
|
||||
echo "Command line options:"
|
||||
@@ -111,8 +111,8 @@ parse_options() {
|
||||
EXT_ARGV=""
|
||||
HAVE_EXT_ARGV=""
|
||||
OPT_ERRS=0
|
||||
OPT_VERSION="no"
|
||||
OPT_HELP="no"
|
||||
OPT_VERSION=""
|
||||
OPT_HELP=""
|
||||
PO_DIR="$TMPDIR/po"
|
||||
|
||||
if [ ! -d "$PO_DIR" ]; then
|
||||
@@ -129,9 +129,23 @@ parse_options() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_parse_pod "$file"
|
||||
_eval_po
|
||||
_parse_config_files
|
||||
_parse_pod "$file" # Parse POD into program option (po) spec files
|
||||
_eval_po # Eval po into existence with default values
|
||||
|
||||
if [ $# -ge 2 ] && [ "$1" = "--config" ]; then
|
||||
shift # --config
|
||||
local user_config_files="$1"
|
||||
shift # that ^
|
||||
local old_ifs="$IFS"
|
||||
IFS=","
|
||||
for user_config_file in $user_config_files; do
|
||||
_parse_config_files "$user_config_file"
|
||||
done
|
||||
IFS="$old_ifs"
|
||||
else
|
||||
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
||||
fi
|
||||
|
||||
_parse_command_line "$@"
|
||||
}
|
||||
|
||||
@@ -218,8 +232,8 @@ _eval_po() {
|
||||
}
|
||||
|
||||
_parse_config_files() {
|
||||
for config_file in "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
|
||||
do
|
||||
|
||||
for config_file in "$@"; do
|
||||
test -f "$config_file" || continue
|
||||
|
||||
while read config_opt; do
|
||||
@@ -228,12 +242,16 @@ _parse_config_files() {
|
||||
|
||||
config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
||||
|
||||
[ "$config_opt" = "" ] && continue
|
||||
|
||||
if ! [ "$HAVE_EXT_ARGV" ]; then
|
||||
config_opt="--$config_opt"
|
||||
fi
|
||||
|
||||
_parse_command_line "$config_opt"
|
||||
|
||||
done < "$config_file"
|
||||
|
||||
|
||||
HAVE_EXT_ARGV="" # reset for each file
|
||||
|
||||
done
|
||||
@@ -1212,6 +1230,13 @@ Collect strace data.
|
||||
|
||||
Collect tcpdump data.
|
||||
|
||||
=item --config
|
||||
|
||||
type: string
|
||||
|
||||
Read this comma-separated list of config files. If specified, this must be the
|
||||
first option on the command line.
|
||||
|
||||
=item --cycles
|
||||
|
||||
type: int; default: 5
|
||||
|
Reference in New Issue
Block a user