shell dot on steroids https://pagure.io/shellfu

exits.sh 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. FFOO_EXITS_OK=0
  3. FFOO_EXITS_NO=1
  4. FFOO_EXITS_USAGE=2
  5. FFOO_EXITS_ERROR=3
  6. FFOO_EXITS_PANIC=4
  7. exit_ok() {
  8. #
  9. # Exit script with success
  10. #
  11. exit $FFOO_EXITS_OK
  12. }
  13. exit_no() {
  14. #
  15. # Exit script with answer "no"
  16. #
  17. exit $FFOO_EXITS_NO
  18. }
  19. exit_usage() {
  20. #
  21. # Exit script with usage error
  22. #
  23. exit $FFOO_EXITS_USAGE
  24. }
  25. exit_error() {
  26. #
  27. # Exit script with generic unexpected error
  28. #
  29. exit $FFOO_EXITS_ERROR
  30. }
  31. exit_panic() {
  32. #
  33. # Exit script in panic (e.g. assert failure, sure bug)
  34. #
  35. exit $FFOO_EXITS_PANIC
  36. }
  37. exits() {
  38. #
  39. # Like exit but will not exit interactive session
  40. #
  41. # fastfoo libs are not intended for use in interactive
  42. # session (one should use fff for that), but for development
  43. # and testing purposes we want to enable it
  44. #
  45. test -z "$PS1" && exit $1
  46. }
  47. exits_ok() {
  48. #
  49. # Exit script with success
  50. #
  51. exits $FFOO_EXITS_OK
  52. }
  53. exits_no() {
  54. #
  55. # Exit script with answer "no"
  56. #
  57. exits $FFOO_EXITS_NO
  58. }
  59. exits_usage() {
  60. #
  61. # Exit script with usage error
  62. #
  63. exits $FFOO_EXITS_USAGE
  64. }
  65. exits_error() {
  66. #
  67. # Exit script with generic unexpected error
  68. #
  69. exits $FFOO_EXITS_ERROR
  70. }
  71. exits_panic() {
  72. #
  73. # Exit script in panic (e.g. assert failure, sure bug)
  74. #
  75. exits $FFOO_EXITS_PANIC
  76. }