Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Unified Diff: src/scripts/common.sh

Issue 1141010: Auxiliary function for args checks. (Closed)
Patch Set: fix typo and reformat comment Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scripts/common.sh
diff --git a/src/scripts/common.sh b/src/scripts/common.sh
index 6c97adc2d299c8f3a61bdd415c86029952cc1293..f869b58e64c3893b0592f5ef03c66e10a0a47318 100644
--- a/src/scripts/common.sh
+++ b/src/scripts/common.sh
@@ -255,6 +255,29 @@ is_whitelisted() {
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_YELLOW="\e[33m"
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698