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.

63 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 - 2010 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" | tr ' ' ',')
  28. printf "%15s %s%s\n" "$name" "${desc:-...}" "${aliases:+ (Alias: ${aliases})}"
  29. done
  30. }
  31. sde_wrapper_command_help() {
  32. cat <<-EOT
  33. Usage: sde <command> <discriminator> [OPTIONS] [ARGUMENTS]
  34. Available Commands:
  35. $( sde_wrapper_command_help_list )
  36. For more information about try: sde <command> --help
  37. EOT
  38. }
  39. # checks if a token is a valid command, of an alias of a valid command
  40. #
  41. sde_wrapper_command() {
  42. local cmdbin=
  43. if [ "$1" != "${1%-*}" ]; then
  44. # trying to cheat, no dashes alowed
  45. return
  46. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  47. # command given explicitly
  48. echo "$1"
  49. else
  50. # given token may be an alias of a valid command
  51. cmdbin=$( grep -l "^#Alias: $1$" `sde_wrapper_command_list` | head -n 1 )
  52. echo $( sde_wrapper_name "$cmdbin" )
  53. fi
  54. }