Browse Source

Moved command detection code from bin/sde to lib/sde-wrapper.in

karasz/new-early
Alejandro Mery 17 years ago
parent
commit
a355b259e1
2 changed files with 47 additions and 18 deletions
  1. +13
    -18
      bin/sde
  2. +34
    -0
      lib/sde-wrapper.in

+ 13
- 18
bin/sde

@ -71,30 +71,25 @@ fi
# load corresponding library for sh scripts # load corresponding library for sh scripts
# #
. "$SDEROOT/lib/libsde.in" . "$SDEROOT/lib/libsde.in"
. "$SDEROOT/lib/sde-wrapper.in"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
command="help" command="help"
elif [ "$1" != "${1%-*}" ]; then
# unknown command
echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
# call help without arguments
set --
command="help"
elif [ -x "$SDEROOT/bin/sde-$1" ]; then
command="$1"; shift
elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
# use alias
command="$( grep -l "^#Alias: $1$" `ls -1d $SDEROOT/bin/sde-* | grep -v 'bin/sde-.*-.*'` 2> /dev/null |
head -n 1 | sed -e 's,.*/sde-,,' )"
shift
else else
# unknown command
echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
# call help without arguments
set --
command="help"
# detect requested command
command="$( sde_wrapper_command "$1" )"
if [ -z "$command" ]; then
# unknown command
echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
# call help without arguments
set --
command="help"
else
shift
fi
fi fi
[ -x "$SDEROOT/bin/sde-$command" ] || [ -x "$SDEROOT/bin/sde-$command" ] ||
echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry." echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry."

+ 34
- 0
lib/sde-wrapper.in

@ -0,0 +1,34 @@
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-wrapper.in
# Copyright (C) 2006 - 2007 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 ---
# list all the valid command wrappers
#
sde_list_command_files() {
ls -1d "$SDEROOT/bin/sde-"* | grep -v 'bin/sde-.*-.*'
}
sde_wrapper_command() {
local cmdbin=
if [ "$1" != "${1%-*}" ]; then
# trying to cheat, no dashes alowed
return
elif [ -x "$SDEROOT/bin/sde-$1" ]; then
# command given explicitly
echo "$1"
else
# given token may be an alias of a valid command
cmdbin=$( grep -l "^#Alias: $1$" `sde_list_command_files` | head -n 1 )
echo "$cmdbin" | sed -e 's,.*/sde-,,'
fi
}

Loading…
Cancel
Save