mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-26 01:02:25 +08:00
Handle --nofoo like --no-foo in parse_options.sh and update the Bash tools.
This commit is contained in:
@@ -351,6 +351,13 @@ _parse_command_line() {
|
|||||||
|
|
||||||
real_opt="$opt"
|
real_opt="$opt"
|
||||||
|
|
||||||
|
if $(echo $opt | grep '^--no[^-]' >/dev/null); then
|
||||||
|
local base_opt=$(echo $opt | sed 's/^--no//')
|
||||||
|
if [ -f "$PT_TMPDIR/po/$base_opt" ]; then
|
||||||
|
opt_is_negated=1
|
||||||
|
opt="$base_opt"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if $(echo $opt | grep '^--no-' >/dev/null); then
|
if $(echo $opt | grep '^--no-' >/dev/null); then
|
||||||
opt_is_negated=1
|
opt_is_negated=1
|
||||||
opt=$(echo $opt | sed 's/^--no-//')
|
opt=$(echo $opt | sed 's/^--no-//')
|
||||||
@@ -358,6 +365,7 @@ _parse_command_line() {
|
|||||||
opt_is_negated=""
|
opt_is_negated=""
|
||||||
opt=$(echo $opt | sed 's/^-*//')
|
opt=$(echo $opt | sed 's/^-*//')
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
||||||
val="$(echo $opt | awk -F= '{print $2}')"
|
val="$(echo $opt | awk -F= '{print $2}')"
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ _parse_command_line() {
|
|||||||
|
|
||||||
real_opt="$opt"
|
real_opt="$opt"
|
||||||
|
|
||||||
|
if $(echo $opt | grep '^--no[^-]' >/dev/null); then
|
||||||
|
local base_opt=$(echo $opt | sed 's/^--no//')
|
||||||
|
if [ -f "$PT_TMPDIR/po/$base_opt" ]; then
|
||||||
|
opt_is_negated=1
|
||||||
|
opt="$base_opt"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if $(echo $opt | grep '^--no-' >/dev/null); then
|
if $(echo $opt | grep '^--no-' >/dev/null); then
|
||||||
opt_is_negated=1
|
opt_is_negated=1
|
||||||
opt=$(echo $opt | sed 's/^--no-//')
|
opt=$(echo $opt | sed 's/^--no-//')
|
||||||
@@ -360,6 +367,7 @@ _parse_command_line() {
|
|||||||
opt_is_negated=""
|
opt_is_negated=""
|
||||||
opt=$(echo $opt | sed 's/^-*//')
|
opt=$(echo $opt | sed 's/^-*//')
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
||||||
val="$(echo $opt | awk -F= '{print $2}')"
|
val="$(echo $opt | awk -F= '{print $2}')"
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ _parse_command_line() {
|
|||||||
|
|
||||||
real_opt="$opt"
|
real_opt="$opt"
|
||||||
|
|
||||||
|
if $(echo $opt | grep '^--no[^-]' >/dev/null); then
|
||||||
|
local base_opt=$(echo $opt | sed 's/^--no//')
|
||||||
|
if [ -f "$PT_TMPDIR/po/$base_opt" ]; then
|
||||||
|
opt_is_negated=1
|
||||||
|
opt="$base_opt"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if $(echo $opt | grep '^--no-' >/dev/null); then
|
if $(echo $opt | grep '^--no-' >/dev/null); then
|
||||||
opt_is_negated=1
|
opt_is_negated=1
|
||||||
opt=$(echo $opt | sed 's/^--no-//')
|
opt=$(echo $opt | sed 's/^--no-//')
|
||||||
@@ -360,6 +367,7 @@ _parse_command_line() {
|
|||||||
opt_is_negated=""
|
opt_is_negated=""
|
||||||
opt=$(echo $opt | sed 's/^-*//')
|
opt=$(echo $opt | sed 's/^-*//')
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
||||||
val="$(echo $opt | awk -F= '{print $2}')"
|
val="$(echo $opt | awk -F= '{print $2}')"
|
||||||
|
|||||||
@@ -360,6 +360,13 @@ _parse_command_line() {
|
|||||||
|
|
||||||
real_opt="$opt"
|
real_opt="$opt"
|
||||||
|
|
||||||
|
if $(echo $opt | grep '^--no[^-]' >/dev/null); then
|
||||||
|
local base_opt=$(echo $opt | sed 's/^--no//')
|
||||||
|
if [ -f "$PT_TMPDIR/po/$base_opt" ]; then
|
||||||
|
opt_is_negated=1
|
||||||
|
opt="$base_opt"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if $(echo $opt | grep '^--no-' >/dev/null); then
|
if $(echo $opt | grep '^--no-' >/dev/null); then
|
||||||
opt_is_negated=1
|
opt_is_negated=1
|
||||||
opt=$(echo $opt | sed 's/^--no-//')
|
opt=$(echo $opt | sed 's/^--no-//')
|
||||||
@@ -367,6 +374,7 @@ _parse_command_line() {
|
|||||||
opt_is_negated=""
|
opt_is_negated=""
|
||||||
opt=$(echo $opt | sed 's/^-*//')
|
opt=$(echo $opt | sed 's/^-*//')
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
||||||
val="$(echo $opt | awk -F= '{print $2}')"
|
val="$(echo $opt | awk -F= '{print $2}')"
|
||||||
|
|||||||
@@ -415,7 +415,18 @@ _parse_command_line() {
|
|||||||
# Save real opt from cmd line for error messages.
|
# Save real opt from cmd line for error messages.
|
||||||
real_opt="$opt"
|
real_opt="$opt"
|
||||||
|
|
||||||
# Strip leading -- or --no- from option.
|
# Handle the --nofoo variant of --no-foo.
|
||||||
|
if $(echo $opt | grep '^--no[^-]' >/dev/null); then
|
||||||
|
local base_opt=$(echo $opt | sed 's/^--no//')
|
||||||
|
# Only long options can be negated, so if there's no spec file
|
||||||
|
# for the base option name, then we've been fooled: the leading
|
||||||
|
# --no is actually part of the option's real name, like --north.
|
||||||
|
if [ -f "$PT_TMPDIR/po/$base_opt" ]; then
|
||||||
|
opt_is_negated=1
|
||||||
|
opt="$base_opt"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Handle normal cases: --option and --no-option.
|
||||||
if $(echo $opt | grep '^--no-' >/dev/null); then
|
if $(echo $opt | grep '^--no-' >/dev/null); then
|
||||||
opt_is_negated=1
|
opt_is_negated=1
|
||||||
opt=$(echo $opt | sed 's/^--no-//')
|
opt=$(echo $opt | sed 's/^--no-//')
|
||||||
@@ -423,6 +434,7 @@ _parse_command_line() {
|
|||||||
opt_is_negated=""
|
opt_is_negated=""
|
||||||
opt=$(echo $opt | sed 's/^-*//')
|
opt=$(echo $opt | sed 's/^-*//')
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Split opt=val pair.
|
# Split opt=val pair.
|
||||||
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
plan 80
|
plan 81
|
||||||
|
|
||||||
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
|
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
|
||||||
TOOL="pt-stalk"
|
TOOL="pt-stalk"
|
||||||
@@ -67,6 +67,15 @@ is "$OPT_INT_OPT" "" "Default int option (neg)"
|
|||||||
is "$OPT_INT_OPT2" "42" "Default int option with default (neg)"
|
is "$OPT_INT_OPT2" "42" "Default int option with default (neg)"
|
||||||
is "$OPT_VERSION" "" "--version (neg)"
|
is "$OPT_VERSION" "" "--version (neg)"
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Negate an option like --nooption.
|
||||||
|
# https://bugs.launchpad.net/percona-toolkit/+bug/954990
|
||||||
|
# ############################################################################
|
||||||
|
|
||||||
|
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --nonoption
|
||||||
|
|
||||||
|
is "$OPT_NOPTION" "" "--nooption negates option like --no-option"
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Short form.
|
# Short form.
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user