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.

85 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. set -e
  18. [ -n "$SDEROOT" ] ||
  19. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  20. . $SDEROOT/lib/libsde.in
  21. help_list() {
  22. local command=
  23. local name= desc= alias=
  24. echo "Available Commands:"
  25. for command in $SDEROOT/bin/sde-*; do
  26. # detect command name
  27. case "$command" in
  28. */sde-*-*) continue ;;
  29. */sde-*) id=$( echo "$command" | sed -e 's,.*/sde-,,' )
  30. ;;
  31. esac
  32. # optional description
  33. desc=$( sed -n -e 's,^#Description: \(.*\)$,\1,p' "$command" )
  34. # and valid aliases
  35. alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' )
  36. echo -e "\t* $id${alias:+\t(${alias%% })}"
  37. if [ -n "$desc" ]; then
  38. echo -e "\t\t$desc"
  39. fi
  40. done
  41. }
  42. help_usage() {
  43. echo "Usage: sde help [<command>]"
  44. }
  45. help_command() {
  46. if [ -r "$SDEROOT/doc/man/sde-$1.1" ]; then
  47. man "$SDEROOT/doc/man/sde-$1.1"
  48. else
  49. echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help."
  50. fi
  51. }
  52. if [ $# -eq 0 -o -z "$1" ]; then
  53. help_list
  54. elif [ $# -gt 1 ]; then
  55. echo_error "Incorrect Syntax."
  56. help_usage
  57. exit 1
  58. elif [ "$1" != "${1%-*}" ]; then
  59. # don't accept subcommands
  60. echo_error "Incorrect Syntax."
  61. help_usage
  62. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  63. help_command "$1"
  64. elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
  65. # use alias
  66. x="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null |
  67. head -n 1 | sed -e 's,.*/sde-,,' )"
  68. help_command "$x"
  69. else
  70. # unknown command
  71. echo_error "Command '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist."
  72. help_list
  73. exit 2
  74. fi