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.
 
 
 
 
 
 

98 lines
2.6 KiB

#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: bin/sde-help
# 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 ---
#Description: Help about the usage of `sde` and the modules
#Alias: --help
#Alias: man
set -e
[ -n "$SDEROOT" ] ||
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. $SDEROOT/lib/libsde.in
help_list() {
local command=
local name= desc= alias= filler=
echo "Available Commands:"
for command in $SDEROOT/bin/sde-*; do
# detect command name
case "$command" in
*/sde-*-*) continue ;;
*/sde-*) id=$( echo "$command" | sed -e 's,.*/sde-,,' )
;;
esac
# Retrieve optional multiple description lines. Prepare
# them for output by having them start with 2 tabs.
desc=$( sed -n -e 's,^#Description: \(.*\)$,\t\t\1,p' "$command" | sed -e 's,\t*$,,' )
# Retrieve all valid aliases, replace line breaks
# with spaces and remove trailing spaces.
alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' | sed -e 's, *$,,' )
# Output the command with its aliases if it has any.
echo -n -e "\t* $id"
if [ -n "${alias}" ]; then
# To allign aliases we use a filler, using tabs
# does not allign correctly.
filler=" "
echo -n -e "${filler:${#id}} (${alias})"
fi
echo
# If there is a description output is as well.
if [ -n "$desc" ]; then
echo -e "$desc"
fi
done
}
help_usage() {
echo "Usage: sde help [<command>]"
}
help_command() {
if [ -r "$SDEROOT/doc/man/sde-$1.1" ]; then
man "$SDEROOT/doc/man/sde-$1.1"
else
echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help."
fi
}
if [ $# -eq 0 -o -z "$1" ]; then
help_list
elif [ $# -gt 1 ]; then
echo_error "Incorrect Syntax."
help_usage
exit 1
elif [ "$1" != "${1%-*}" ]; then
# don't accept subcommands
echo_error "Incorrect Syntax."
help_usage
elif [ -x "$SDEROOT/bin/sde-$1" ]; then
help_command "$1"
elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
# use alias
x="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null |
head -n 1 | sed -e 's,.*/sde-,,' )"
help_command "$x"
else
# unknown command
echo_error "Command '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist."
help_list
exit 2
fi