common.sh 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Color output encodings.
  6. COL_RED='\E[31;1m'
  7. COL_GREEN='\E[32;1m'
  8. COL_YELLOW='\E[33;1m'
  9. COL_BLUE='\E[34;1m'
  10. COL_STOP='\E[0;m'
  11. # args: [message]
  12. green() {
  13. echo -e "${COL_GREEN}$*${COL_STOP}"
  14. }
  15. # args: [message]
  16. yellow() {
  17. echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}"
  18. }
  19. # args: [message]
  20. red() {
  21. echo -e "${COL_RED}$*${COL_STOP}"
  22. }
  23. # args: [nested level] [message]
  24. error() {
  25. local lev=${1:-}
  26. case "${1:-}" in
  27. [0-9]*)
  28. lev=$1
  29. shift
  30. ;;
  31. *) lev=0
  32. ;;
  33. esac
  34. local x=$(caller $lev)
  35. local cline="${x%% *}"
  36. local cfile="${x#* }"
  37. cfile="${cfile##*/}"
  38. local args="$*"
  39. local spacer="${args:+: }"
  40. red "at ${cfile}, line ${cline}${spacer}${args}" 1>&2
  41. exit 1
  42. }