imapfilter convenience wrapper

target.sh 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # MKit - simple install helper
  3. # See LICENSE file for copyright and license details.
  4. mkit_import ini
  5. mkit_import plugin
  6. target__ls() {
  7. #
  8. # List valid routes
  9. #
  10. target__map | cut -d' ' -f1
  11. }
  12. target__map() {
  13. #
  14. # List valid routes and corresponding module:functions
  15. #
  16. #shellcheck disable=SC2291
  17. {
  18. echo _mkit_builddata build:_mkit_builddata
  19. echo _mkit_inidata build:_mkit_inidata
  20. echo _mkit_metadata build:_mkit_metadata
  21. echo _mkit_show_builddata build:_mkit_show_builddata
  22. echo _mkit_show_metadata build:_mkit_show_metadata
  23. echo build build:build
  24. echo clean build:clean
  25. echo dist build:dist
  26. echo install deploy:install
  27. echo release release:release
  28. echo release_x release:release_x
  29. echo release_y release:release_y
  30. echo release_z release:release_z
  31. echo uninstall deploy:uninstall
  32. echo vbump release:vbump
  33. echo vbump_x release:vbump_x
  34. echo vbump_y release:vbump_y
  35. echo vbump_z release:vbump_z
  36. }
  37. }
  38. target__isvalid() {
  39. #
  40. # True if target $1 is valid
  41. #
  42. local target=$1
  43. target__map | grep -qwe "^$target"
  44. }
  45. target__route() {
  46. #
  47. # Call correct function based on $1
  48. #
  49. local target=$1
  50. local es
  51. if target__isvalid "$target"; then
  52. target__run "$target"; es=$?
  53. elif plugin__isvalid "$target"; then
  54. plugin__handle "$target" main; es=$?
  55. else
  56. {
  57. echo "usage: $(basename "$0") TARGET"
  58. echo
  59. echo "valid targets (built-in):"
  60. target__ls | sed 's/^/ /'
  61. echo
  62. echo "valid targets (from plugins):"
  63. plugin__ls | sed 's/^/ /'
  64. } >&2
  65. es=2
  66. fi
  67. return "$es"
  68. }
  69. target__run() {
  70. #
  71. # Run target $1
  72. #
  73. local target=$1
  74. local module
  75. local fn
  76. read -r module fn <<<"$(
  77. target__map \
  78. | tr : ' ' \
  79. | grep -we "^$target" \
  80. | cut -d' ' -f2-
  81. )"
  82. debug_var target module fn
  83. mkit_import "$module"
  84. "$fn"
  85. }