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.

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