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.

98 lines
2.6 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-help
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Help about the usage of `sde` and the modules
  16. #Alias: --help
  17. #Alias: man
  18. set -e
  19. [ -n "$SDEROOT" ] ||
  20. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  21. . $SDEROOT/lib/libsde.in
  22. help_list() {
  23. local command=
  24. local name= desc= alias= filler=
  25. echo "Available Commands:"
  26. for command in $SDEROOT/bin/sde-*; do
  27. # detect command name
  28. case "$command" in
  29. */sde-*-*) continue ;;
  30. */sde-*) id=$( echo "$command" | sed -e 's,.*/sde-,,' )
  31. ;;
  32. esac
  33. # Retrieve optional multiple description lines. Prepare
  34. # them for output by having them start with 2 tabs.
  35. desc=$( sed -n -e 's,^#Description: \(.*\)$,\t\t\1,p' "$command" | sed -e 's,\t*$,,' )
  36. # Retrieve all valid aliases, replace line breaks
  37. # with spaces and remove trailing spaces.
  38. alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' | sed -e 's, *$,,' )
  39. # Output the command with its aliases if it has any.
  40. echo -n -e "\t* $id"
  41. if [ -n "${alias}" ]; then
  42. # To allign aliases we use a filler, using tabs
  43. # does not allign correctly.
  44. filler=" "
  45. echo -n -e "${filler:${#id}} (${alias})"
  46. fi
  47. echo
  48. # If there is a description output is as well.
  49. if [ -n "$desc" ]; then
  50. echo -e "$desc"
  51. fi
  52. done
  53. }
  54. help_usage() {
  55. echo "Usage: sde help [<command>]"
  56. }
  57. help_command() {
  58. if [ -r "$SDEROOT/doc/man/sde-$1.1" ]; then
  59. man "$SDEROOT/doc/man/sde-$1.1"
  60. else
  61. echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help."
  62. fi
  63. }
  64. if [ $# -eq 0 -o -z "$1" ]; then
  65. help_list
  66. elif [ $# -gt 1 ]; then
  67. echo_error "Incorrect Syntax."
  68. help_usage
  69. exit 1
  70. elif [ "$1" != "${1%-*}" ]; then
  71. # don't accept subcommands
  72. echo_error "Incorrect Syntax."
  73. help_usage
  74. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  75. help_command "$1"
  76. elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
  77. # use alias
  78. x="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null |
  79. head -n 1 | sed -e 's,.*/sde-,,' )"
  80. help_command "$x"
  81. else
  82. # unknown command
  83. echo_error "Command '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist."
  84. help_list
  85. exit 2
  86. fi