mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 21:46:58 +02:00
Auxiliary function for args checks.
Review URL: http://codereview.chromium.org/1141010
This commit is contained in:
parent
9ef57d996b
commit
1f82e12eae
23
common.sh
23
common.sh
@ -255,6 +255,29 @@ is_whitelisted() {
|
|||||||
test $count -ne 0
|
test $count -ne 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check that all arguments are flags; that is, there are no remaining arguments
|
||||||
|
# after parsing from shflags. Allow (with a warning) a single empty-string
|
||||||
|
# argument.
|
||||||
|
#
|
||||||
|
# TODO: fix buildbot so that it doesn't pass the empty-string parameter,
|
||||||
|
# then change this function.
|
||||||
|
#
|
||||||
|
# Usage: check_flags_only_and_allow_null_arg "$@" && set --
|
||||||
|
function check_flags_only_and_allow_null_arg {
|
||||||
|
do_shift=1
|
||||||
|
if [[ $# == 1 && -z "$@" ]]; then
|
||||||
|
echo "$0: warning: ignoring null argument" >&2
|
||||||
|
shift
|
||||||
|
do_shift=0
|
||||||
|
fi
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
echo "error: invalid arguments: \"$@\"" >&2
|
||||||
|
flags_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return $do_shift
|
||||||
|
}
|
||||||
|
|
||||||
V_RED="\e[31m"
|
V_RED="\e[31m"
|
||||||
V_YELLOW="\e[33m"
|
V_YELLOW="\e[33m"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user