From dbe855753a798bc83fac4ac6a4bb72bacbd1c1af Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 4 May 2007 16:43:57 +0000 Subject: [PATCH] * converted `sde help` into bin/sde-help, and lib/sde-help.in only for shared functions * introduced help_command() function on lib/sde-help.in, showing usage from lib/sde-$command.hlp git-svn-id: svn://svn.opensde.net/opensde/opensde/trunk@20974 10447126-35f2-4685-b0cf-6dd780d3921f --- bin/sde-help | 45 ++++++++++++++++++++++++++++++++++++++ lib/sde-help.in | 57 +++++++++++++------------------------------------ 2 files changed, 60 insertions(+), 42 deletions(-) create mode 100755 bin/sde-help diff --git a/bin/sde-help b/bin/sde-help new file mode 100755 index 0000000..32e3c1e --- /dev/null +++ b/bin/sde-help @@ -0,0 +1,45 @@ +#!/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 + +set -e + +[ -n "$SDEROOT" ] || + export SDEROOT=$( cd "${0%/*}/.."; pwd -P ) + +. $SDEROOT/lib/libsde.in +. $SDEROOT/lib/sde-help.in + +if [ $# -eq 0 -o -z "$1" ]; then + help_list +elif [ $# -gt 1 ]; then + echo_error "Incorrect Syntax." + help_command 'help' + exit 1 +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 diff --git a/lib/sde-help.in b/lib/sde-help.in index 7968153..cf02723 100644 --- a/lib/sde-help.in +++ b/lib/sde-help.in @@ -15,18 +15,26 @@ #Description: Help about the usage of `sde` and the modules #Alias: --help +help_command() { + if [ -r "$SDEROOT/lib/sde-$1.hlp" ]; then + grep -v '^#' "$SDEROOT/lib/sde-$1.hlp" + else + echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help." + fi +} + help_list() { - local module= + local command= local name= desc= alias= - echo "Available Modules:" - for module in $SDEROOT/lib/sde-*.in; do - # detect module name - id=$( echo "$module" | sed -e 's,.*/sde-,,' -e 's,.in$,,' ) + echo "Available Commands:" + for command in $SDEROOT/bin/sde-*; do + # detect command name + id=$( echo "$command" | sed -e 's,.*/sde-,,' ) # optional description - desc=$( sed -n -e 's,^#Description: \(.*\)$,\1,p' "$module" ) + desc=$( sed -n -e 's,^#Description: \(.*\)$,\1,p' "$command" ) # and valid aliases - alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$module" | tr '\n' ' ' ) + alias=$( sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' ) echo -e "\t* $id${alias:+\t(${alias%% })}" if [ -n "$desc" ]; then @@ -34,38 +42,3 @@ help_list() { fi done } - -if [ "$module" == "help" ]; then - # main action - if [ $# -eq 0 -o -z "$1" ]; then - help_list - elif [ $# -gt 1 ]; then - echo_error "Incorrect Syntax." - help_usage - exit 1 - elif [ -r "$SDEROOT/lib/sde-$1.in" ]; then - [ "$1" == "help" ] || . "$SDEROOT/lib/sde-$1.in" - - if type -t "${1}_usage" > /dev/null; then - "${1}_usage" - else - echo_warning "'$COLOR_MESSAGE${1}$COLOR_NORMAL' doesn't provide help." - fi - elif grep -q "^#Alias: $1$" $SDEROOT/lib/sde-*.in 2> /dev/null; then - # use alias - x="$( grep -l "^#Alias: $1$" $SDEROOT/lib/sde-*.in 2> /dev/null | - head -n 1 | sed -e 's,.*/sde-,,' -e 's,.in$,,' )" - [ "$x" == "help" ] || . "$SDEROOT/lib/sde-$x.in" - - if type -t "${x}_usage" > /dev/null; then - "${x}_usage" - else - echo_warning "'$COLOR_MESSAGE${x}$COLOR_NORMAL' doesn't provide help." - fi - else - # unknown module - echo_error "Module '$COLOR_MESSAGE$1$COLOR_NORMAL' doesn't exist." - help_list - exit 2 - fi -fi