Changed scripts/Config to grab the version from lib/libsde.in instead of lib/functions.in
[opensde-nopast.git] / lib / sde-wrapper-discriminator.in
bloba6a785cace56b9f81be30e539af99f37e132a796
1 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # Filename: lib/sde-wrapper-discriminator.in
5 # Copyright (C) 2008 The OpenSDE Project
7 # More information can be found in the files COPYING and README.
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 ---
15 # include the generic sde_wrapper functions
16 . "$SDEROOT/lib/sde-wrapper.in"
18 # list all the valid discriminators for a given command
20 sde_wrapper_discriminator_list() {
21         ls -1d "$SDEROOT/bin/sde-$1-"* 2> /dev/null
24 # return the usage of every discriminator
25 sde_wrapper_discriminator_help() {
26         local toy= name= desc= aliases=
27         cat <<-EOT
28         Usage:  sde $1 <discriminator> [OPTIONS] [ARGUMENTS]
30         Available Discriminators:
31         EOT
32         for toy in $( sde_wrapper_discriminator_list "$1" ); do
33                 name=$( sde_wrapper_name "$toy" )
34                 desc=$( sde_wrapper_desc "$toy" )
35                 aliases=$( sde_wrapper_aliases "$toy" )
37                 printf "%15s %s%s\n" "$name" "${desc:-...}" "${aliases:+ (Alias: ${aliases// /,})}"
38         done
39         cat <<-EOT
41         For more information try: sde $1 <discriminator> --help
42         EOT
45 sde_wrapper_discriminator() {
46         local combin= command="$1"; shift
47         local discriminators=$( sde_wrapper_discriminator_list $command )
49         if [ "$1" != "${1%-*}" ]; then
50                 # trying to cheat, no dashes alowed
51                 return
52         elif [ -x "$SDEROOT/bin/sde-$command-$1" ]; then
53                 # discriminator given explicitly
54                 echo "$1"
55         elif [ -n "$discriminators" ]; then
56                 # given token may be an alias of a valid discriminator for this command
57                 combin=$( grep -l "^#Alias: $1$" $discriminators | head -n 1 )
58                 echo $( sde_wrapper_name "$combin" )
59         fi