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.

66 lines
1.8 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-wrapper-command.in
  5. # Copyright (C) 2006 - 2008 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. # include the generic sde_wrapper functions
  15. . "$SDEROOT/lib/sde-wrapper.in"
  16. # list all the valid command wrappers
  17. #
  18. sde_wrapper_command_list() {
  19. ls -1d "$SDEROOT/bin/sde-"* | grep -v 'bin/sde-.*-.*'
  20. }
  21. sde_wrapper_command_help_list() {
  22. local command=
  23. local name= desc= alias=
  24. for command in $( sde_wrapper_command_list ); do
  25. name=$( sde_wrapper_name "$command" )
  26. desc=$( sde_wrapper_desc "$command" )
  27. aliases=$( sde_wrapper_aliases "$command" )
  28. echo -e "\t* $name${aliases:+\t(${aliases})}"
  29. if [ -n "$desc" ]; then
  30. echo -e "\t\t$desc"
  31. fi
  32. done
  33. }
  34. sde_wrapper_command_help() {
  35. cat <<-EOT
  36. Usage: sde <command> <discriminator> [OPTIONS] [ARGUMENTS]
  37. Available Commands:
  38. $( sde_wrapper_command_help_list )
  39. For more information about try: sde <command> --help
  40. EOT
  41. }
  42. # checks if a token is a valid command, of an alias of a valid command
  43. #
  44. sde_wrapper_command() {
  45. local cmdbin=
  46. if [ "$1" != "${1%-*}" ]; then
  47. # trying to cheat, no dashes alowed
  48. return
  49. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  50. # command given explicitly
  51. echo "$1"
  52. else
  53. # given token may be an alias of a valid command
  54. cmdbin=$( grep -l "^#Alias: $1$" `sde_wrapper_command_list` | head -n 1 )
  55. echo "$cmdbin" | sed -e 's,.*/sde-,,'
  56. fi
  57. }