-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibdebug.sh
More file actions
25 lines (20 loc) · 914 Bytes
/
libdebug.sh
File metadata and controls
25 lines (20 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (c) 2013, Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# A bash library of locker debugging
#
q() { "$@" 2>/dev/null ; } # execute a cmd and quiet the stderr
debug_date() { # > date | nothing
[ "$DEBUG" = "DEBUG" -o "$DEBUG" = "INFO" ] && echo "$(date +'%F %T %N') "
}
debug_stderr() { echo "$(debug_date)$@" >&2 ; } # message >&2 [date] message
debug() { [ "$DEBUG" = "DEBUG" ] && debug_stderr "$@" ; }
info() { debug "$@" ; [ "$DEBUG" = "INFO" ] && debug_stderr "$@" ; }
error() { debug_stderr "Error - $1" ; exit $2 ; }
args() { # action needed optional [args]...
local func=$1 needed=$2 optional=$3 n s min=0 supplied=0 ; shift 3
for n in $needed ; do min=$((min+1)) ; done
for s in "$@" ; do supplied=$((supplied +1)) ; done
[ $supplied -ge $min ] && return
usage "'$func' takes <$needed> [$optional], given ($*)"
}