This commit is contained in:
parent
374ac3aeb9
commit
9241f0abb5
29
script
29
script
|
@ -1,5 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s [-h]\n" "$0"
|
||||
}
|
||||
|
@ -30,15 +32,40 @@ main() {
|
|||
case "${option}" in
|
||||
h) help; exit 0;;
|
||||
f) FOO="$OPTARG";;
|
||||
*) usage; exit 1;;
|
||||
?) log -l error "$(usage)"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
FOO="${FOO:-defaultValue}"
|
||||
|
||||
# log [-t] [-l debug|error|info] message
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
log() {
|
||||
LEVEL=info
|
||||
TIME=
|
||||
|
||||
while getopts "tl:" option; do
|
||||
case "${option}" in
|
||||
l) LEVEL="$OPTARG"; shift $((OPTIND-1));;
|
||||
t) TIME="$(printf "[%s] " "$(date +'%Y-%m-%dT%H:%m:%S.%s')")"; shift $((OPTIND-1));;
|
||||
*) exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -t 2 ] && [ -z "${NO_COLOR-}" ]; then
|
||||
case "${LEVEL}" in
|
||||
debug) COLOR="$(tput setaf 3)";;
|
||||
error) COLOR="$(tput setaf 1)";;
|
||||
*) COLOR="$(tput sgr0)"
|
||||
esac
|
||||
fi
|
||||
|
||||
printf "%s%s%s\n" "${COLOR:-}" "${TIME:-}" "$*" >&2
|
||||
}
|
||||
|
||||
trap on_interrupt INT
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in a new issue