From f19d4a79c48b967622da9463c36568258d5ed14f Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sun, 27 Jan 2008 00:26:29 -0300 Subject: [PATCH] Splitted lib/sde-wrapper.in into lib/sde-wrapper-command.in The first keeps the functions interesting for `sde` and `sde-$command`, the second those only interesing to `sde` --- lib/sde-wrapper-command.in | 66 ++++++++++++++++++++++++++++++++++++++ lib/sde-wrapper.in | 39 ++++++---------------- 2 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 lib/sde-wrapper-command.in diff --git a/lib/sde-wrapper-command.in b/lib/sde-wrapper-command.in new file mode 100644 index 0000000..5482ab0 --- /dev/null +++ b/lib/sde-wrapper-command.in @@ -0,0 +1,66 @@ +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: lib/sde-wrapper-command.in +# Copyright (C) 2006 - 2008 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 command wrappers +# +sde_wrapper_command_list() { + ls -1d "$SDEROOT/bin/sde-"* | grep -v 'bin/sde-.*-.*' +} + +sde_wrapper_command_help_list() { + local command= + local name= desc= alias= + + for command in $( sde_wrapper_command_list ); do + name=$( sde_wrapper_name "$command" ) + desc=$( sde_wrapper_desc "$command" ) + aliases=$( sde_wrapper_aliases "$command" ) + + echo -e "\t* $name${aliases:+\t(${aliases})}" + if [ -n "$desc" ]; then + echo -e "\t\t$desc" + fi + done +} + +sde_wrapper_command_help() { + cat <<-EOT + Usage: sde [OPTIONS] [ARGUMENTS] + + Available Commands: + $( sde_wrapper_command_help_list ) + + For more information about try: sde --help + EOT +} + +# checks if a token is a valid command, of an alias of a valid command +# +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_wrapper_command_list` | head -n 1 ) + echo "$cmdbin" | sed -e 's,.*/sde-,,' + fi +} diff --git a/lib/sde-wrapper.in b/lib/sde-wrapper.in index 31646a1..f7b0cb8 100644 --- a/lib/sde-wrapper.in +++ b/lib/sde-wrapper.in @@ -2,7 +2,7 @@ # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/sde-wrapper.in -# Copyright (C) 2006 - 2008 The OpenSDE Project +# Copyright (C) 2008 The OpenSDE Project # # More information can be found in the files COPYING and README. # @@ -12,39 +12,18 @@ # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- -# list all the valid command wrappers -# -sde_wrapper_command_list() { - ls -1d "$SDEROOT/bin/sde-"* | grep -v 'bin/sde-.*-.*' +# returns the name of a discriminator or command based of the filename +sde_wrapper_name() { + echo "${1##*-}" } -# returns the name of a command file -sde_wrapper_command_name() { - echo "$1" | sed -e 's,.*/sde-,,' -} - -# returns the description of a command file -sde_wrapper_command_desc() { +# returns the description of the wrapper +sde_wrapper_desc() { sed -n -e 's,^#Description: \(.*\)$,\1,p' "$1" | head -n 1 } -# returns an space delimited list of aliases of this command file -sde_wrapper_command_aliases() { - sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$command" | tr '\n' ' ' | +# returns an space delimited list of aliases of a wrapper +sde_wrapper_aliases() { + sed -n -e 's,^#Alias: \([^ ]*\)$,\1,p' "$1" | tr '\n' ' ' | sed -e 's/^ *//' -e 's/ *$//' } - -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_wrapper_command_list` | head -n 1 ) - echo "$cmdbin" | sed -e 's,.*/sde-,,' - fi -}