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.

86 lines
2.1 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=
  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. # optional description
  34. desc=$( sed -n -e 's,^#Description: \(.*\)$,\1,p' "$command" )
  35. # and valid aliases
  36. alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' )
  37. echo -e "\t* $id${alias:+\t(${alias%% })}"
  38. if [ -n "$desc" ]; then
  39. echo -e "\t\t$desc"
  40. fi
  41. done
  42. }
  43. help_usage() {
  44. echo "Usage: sde help [<command>]"
  45. }
  46. help_command() {
  47. if [ -r "$SDEROOT/doc/man/sde-$1.1" ]; then
  48. man "$SDEROOT/doc/man/sde-$1.1"
  49. else
  50. echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help."
  51. fi
  52. }
  53. if [ $# -eq 0 -o -z "$1" ]; then
  54. help_list
  55. elif [ $# -gt 1 ]; then
  56. echo_error "Incorrect Syntax."
  57. help_usage
  58. exit 1
  59. elif [ "$1" != "${1%-*}" ]; then
  60. # don't accept subcommands
  61. echo_error "Incorrect Syntax."
  62. help_usage
  63. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  64. help_command "$1"
  65. elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
  66. # use alias
  67. x="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null |
  68. head -n 1 | sed -e 's,.*/sde-,,' )"
  69. help_command "$x"
  70. else
  71. # unknown command
  72. echo_error "Command '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist."
  73. help_list
  74. exit 2
  75. fi