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.

60 lines
1.9 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-wrapper-discriminator.in
  5. # Copyright (C) 2008 - 2009 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 discriminators for a given command
  17. #
  18. sde_wrapper_discriminator_list() {
  19. ls -1d "$SDEROOT/bin/sde-$1-"* 2> /dev/null
  20. }
  21. # return the usage of every discriminator
  22. sde_wrapper_discriminator_help() {
  23. local toy= name= desc= aliases=
  24. cat <<-EOT
  25. Usage: sde $1 <discriminator> [OPTIONS] [ARGUMENTS]
  26. Available Discriminators:
  27. EOT
  28. for toy in $( sde_wrapper_discriminator_list "$1" ); do
  29. name=$( sde_wrapper_name "$toy" )
  30. desc=$( sde_wrapper_desc "$toy" )
  31. aliases=$( sde_wrapper_aliases "$toy" | tr ' ' ',')
  32. printf "%15s %s%s\n" "$name" "${desc:-...}" "${aliases:+ (Alias: $aliases)}"
  33. done
  34. cat <<-EOT
  35. For more information try: sde $1 <discriminator> --help
  36. EOT
  37. }
  38. sde_wrapper_discriminator() {
  39. local combin= command="$1"; shift
  40. local discriminators="$(sde_wrapper_discriminator_list $command)"
  41. if [ "$1" != "${1%-*}" ]; then
  42. # trying to cheat, no dashes alowed
  43. return
  44. elif [ -x "$SDEROOT/bin/sde-$command-$1" ]; then
  45. # discriminator given explicitly
  46. echo "$1"
  47. elif [ -n "$discriminators" ]; then
  48. # given token may be an alias of a valid discriminator for this command
  49. combin=$(grep -l "^#Alias:[\t ]\+\(.*[\t ]\)\?$1\([\t ].*\)\?\$" $discriminators | head -n 1)
  50. echo $( sde_wrapper_name "$combin" )
  51. fi
  52. }