imapfilter convenience wrapper

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #shellcheck disable=SC2034
  3. # mkit - simple install helper
  4. # See LICENSE file for copyright and license details.
  5. usage() {
  6. print_help >&2
  7. test $# -gt 0 && {
  8. printf >&2 '%s\n' "" "$@"
  9. }
  10. exit 2
  11. }
  12. print_help() {
  13. local self=${0##*/}
  14. local lines=(
  15. "usage:"
  16. " $self TARGET"
  17. " $self -i|--ini-1value PATH"
  18. " $self -I|--ini-values PATH"
  19. " $self --list-plugins"
  20. " $self --list-targets"
  21. " $self -V|--version-semver"
  22. " $self --version"
  23. ""
  24. "commands:"
  25. " TARGET build target TARGET"
  26. " -i PATH print single-line value at INI path PATH"
  27. " (ignore all but last instance of this"
  28. " value in the INI)"
  29. " -I PATH like -i, but list all instances, one per line"
  30. " (multi-line values)"
  31. " --list-plugins print list of found plugins and exit"
  32. " --list-targets print list of valid targets and exit"
  33. " -V|--version print version (in SemVer format) and exit"
  34. " --help print this help text and exit"
  35. ""
  36. )
  37. printf '%s\n' "${lines[@]}"
  38. echo "valid targets (built-in):"
  39. target__ls | sed 's/^/ /'
  40. echo
  41. echo "valid targets (from plugins):"
  42. plugin__ls | sed 's/^/ /'
  43. }
  44. init_core() {
  45. #
  46. # Load core module (or die)
  47. #
  48. #shellcheck disable=SC1090,SC1091
  49. . "$MKIT_DIR/include/mkit.sh" \
  50. && . "$MKIT_DIR/include/vars.sh" \
  51. && return 0
  52. echo "failed to load core; check if MKIT_DIR is set properly: $MKIT_DIR" >&2
  53. exit 9
  54. }
  55. #
  56. # Path to MKit dir (where 'include' is)
  57. #
  58. MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
  59. just_ini() {
  60. #
  61. # Just do one mkit.ini operation $1
  62. #
  63. local op=$1
  64. local key=$2
  65. mkit_init || return $?
  66. ini "$op" "$key"
  67. }
  68. main () {
  69. init_core
  70. case "$1" in
  71. -V|--version) echo "$MKIT_VERSION"; exit 0 ;;
  72. -i|--ini-1value) just_ini 1value "$2"; exit $? ;;
  73. -I|--ini-values) just_ini values "$2"; exit $? ;;
  74. --ini-lskeys) just_ini lskeys "$2"; exit $? ;;
  75. --ini-lssect) just_ini lssect "$2"; exit $? ;;
  76. --ini-sec) just_ini sec "$2"; exit $? ;;
  77. --list-targets) mkit_init; target__ls; plugin__ls; exit 0 ;;
  78. --list-plugins) mkit_init; plugin__ls; exit 0 ;;
  79. --help) print_help; exit 0 ;;
  80. -*) usage "unknown argument: $1" ;;
  81. esac
  82. test "$#" -gt 0 || usage
  83. mkit_init
  84. target__route "$@"
  85. }
  86. main "$@"