OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-help.in
  5. # Copyright (C) 2006 - 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. #Description: Help about the usage of `sde` and the modules
  15. #Alias: --help
  16. help_list() {
  17. local module=
  18. local name= desc= alias=
  19. echo "Available Modules:"
  20. for module in $SDEROOT/lib/sde-*.in; do
  21. # detect module name
  22. id=$( echo "$module" | sed -e 's,.*/sde-,,' -e 's,.in$,,' )
  23. # optional description
  24. desc=$( sed -n -e 's,^#Description: \(.*\)$,\1,p' "$module" )
  25. # and valid aliases
  26. alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$module" | tr '\n' ' ' )
  27. echo -e "\t* $id${alias:+\t(${alias%% })}"
  28. if [ -n "$desc" ]; then
  29. echo -e "\t\t$desc"
  30. fi
  31. done
  32. }
  33. if [ "$module" == "help" ]; then
  34. # main action
  35. if [ $# -eq 0 -o -z "$1" ]; then
  36. help_list
  37. elif [ $# -gt 1 ]; then
  38. echo_error "Incorrect Syntax."
  39. help_usage
  40. exit 1
  41. elif [ -r "$SDEROOT/lib/sde-$1.in" ]; then
  42. [ "$1" == "help" ] || . "$SDEROOT/lib/sde-$1.in"
  43. if type -t "${1}_usage" > /dev/null; then
  44. "${1}_usage"
  45. else
  46. echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help."
  47. fi
  48. elif grep -q "^#Alias: $1$" $SDEROOT/lib/sde-*.in 2> /dev/null; then
  49. # use alias
  50. x="$( grep -l "^#Alias: $1$" $SDEROOT/lib/sde-*.in 2> /dev/null |
  51. head -n 1 | sed -e 's,.*/sde-,,' -e 's,.in$,,' )"
  52. [ "$x" == "help" ] || . "$SDEROOT/lib/sde-$x.in"
  53. if type -t "${x}_usage" > /dev/null; then
  54. "${x}_usage"
  55. else
  56. echo_warning "'$COLOR_MESSAGE${x}$COLOR_NORMAL' doesn't provide help."
  57. fi
  58. else
  59. # unknown module
  60. echo_error "Module '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist."
  61. help_list
  62. exit 2
  63. fi
  64. fi