# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/sde-wrapper-discriminator.in # Copyright (C) 2008 - 2009 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- # include the generic sde_wrapper functions . "$SDEROOT/lib/sde-wrapper.in" # list all the valid discriminators for a given command # sde_wrapper_discriminator_list() { ls -1d "$SDEROOT/bin/sde-$1-"* 2> /dev/null } # return the usage of every discriminator sde_wrapper_discriminator_help() { local toy= name= desc= aliases= cat <<-EOT Usage: sde $1 [OPTIONS] [ARGUMENTS] Available Discriminators: EOT for toy in $( sde_wrapper_discriminator_list "$1" ); do name=$( sde_wrapper_name "$toy" ) desc=$( sde_wrapper_desc "$toy" ) aliases=$( sde_wrapper_aliases "$toy" | tr ' ' ',') printf "%15s %s%s\n" "$name" "${desc:-...}" "${aliases:+ (Alias: $aliases)}" done cat <<-EOT For more information try: sde $1 --help EOT } sde_wrapper_discriminator() { local combin= command="$1"; shift local discriminators="$(sde_wrapper_discriminator_list $command)" if [ "$1" != "${1%-*}" ]; then # trying to cheat, no dashes alowed return elif [ -x "$SDEROOT/bin/sde-$command-$1" ]; then # discriminator given explicitly echo "$1" elif [ -n "$discriminators" ]; then # given token may be an alias of a valid discriminator for this command combin=$(grep -l "^#Alias:[\t ]\+\(.*[\t ]\)\?$1\([\t ].*\)\?\$" $discriminators | head -n 1) echo $( sde_wrapper_name "$combin" ) fi }