diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-05-12 19:23:16 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-05-12 19:23:16 -0400 |
commit | 272f57b2a4d9f2c8d5ac3c46962f25c55dfbb270 (patch) | |
tree | 90055d8d7e394ae5377200ee2ec00afa4b861f0b | |
parent | b2c326dc625c0ee7cdfb5763b036db6893db9efd (diff) |
simplify by moving usage() into jh-help, jh no longer needs to be included
-rw-r--r-- | jh-help.sh | 30 | ||||
-rw-r--r-- | jh-list-commands.sh | 16 | ||||
-rw-r--r-- | jh-mvn-basename.sh | 3 | ||||
-rw-r--r-- | jh-mvn-install.sh | 3 | ||||
-rw-r--r-- | jh-mvn-localrepo.sh | 9 | ||||
-rw-r--r-- | jh.sh | 41 |
6 files changed, 54 insertions, 48 deletions
@@ -1,8 +1,30 @@ #!/bin/bash -. jh + +stem=jh + +master_help() { + echo "Usage: $jh_short <command> [command-specific-arguments]" + echo "Java helper for PKGBUILDs" + echo "" + jh-list-commands|sed 's/./ &/' +} + +generic_help() { + local cmd=$1 + cmd=${cmd##*/} + cmd=${cmd#$stem-} + + file=`find ${PATH//:/ } -type f -name "$stem-$cmd.help.txt" 2>/dev/null` + if [[ -r $file ]]; then + sed "s|@cmd@|$jh_short|g" "$file" + else + echo "$jh_short: Cannot find help file for '$cmd'" >> /dev/stderr + exit 1 + fi +} case $# in - 0) usage ''; exit 0;; - 1) usage "$1"; exit 0;; - *) usage help; exit 1;; + 0) master_help; exit 0;; + 1) generic_help "$1"; exit 0;; + *) generic_help help; exit 1;; esac diff --git a/jh-list-commands.sh b/jh-list-commands.sh index 143f6e7..66ce5aa 100644 --- a/jh-list-commands.sh +++ b/jh-list-commands.sh @@ -1,13 +1,17 @@ #!/bin/bash -. jh if [[ $# > 0 ]]; then - usage + jh-help $0 >>/dev/stderr exit 1 fi -for cmd_help in "$JH_PATH"/*.help.txt; do - cmd=`echo "$cmd_help"|sed -r 's|.*/jh-(.*)\.help\.txt$|\1|'` +stem=jh + +find ${PATH//:/ } -type f -name "$stem-*.help.txt" 2>/dev/null | +while read cmd_help; do + cmd=$cmd_help + cmd=${cmd%.help.txt} + cmd=${cmd##*/$stem-} help=`sed -n 2p "$cmd_help"` - printf "%-20s %s\n" "$cmd" "$help" -done + printf '%-20s %s\n' "$cmd" "$help" +done | sort diff --git a/jh-mvn-basename.sh b/jh-mvn-basename.sh index 776cc0e..eff78aa 100644 --- a/jh-mvn-basename.sh +++ b/jh-mvn-basename.sh @@ -1,8 +1,7 @@ #!/bin/bash -. jh if [[ $# != 3 ]]; then - usage + jh-help $0 >>/dev/stderr exit 1 fi diff --git a/jh-mvn-install.sh b/jh-mvn-install.sh index 23c0d6a..41aefcc 100644 --- a/jh-mvn-install.sh +++ b/jh-mvn-install.sh @@ -1,8 +1,7 @@ #!/bin/bash -. jh if [[ $# != 5 ]]; then - usage + jh-help $0 >>/dev/stderr exit 1 fi diff --git a/jh-mvn-localrepo.sh b/jh-mvn-localrepo.sh index 14ea778..e74e7a9 100644 --- a/jh-mvn-localrepo.sh +++ b/jh-mvn-localrepo.sh @@ -1,13 +1,12 @@ #!/bin/bash -. jh if [[ $# > 0 ]]; then - usage - exit 1 + jh-help $0 >>/dev/stderr + exit 1 fi if [ -e /etc/maven/settings.xml ]; then - xml sel -T -t -v "//*[local-name()='localRepository']" -n /etc/maven/settings.xml + xml sel -T -t -v "//*[local-name()='localRepository']" -n /etc/maven/settings.xml else - echo /usr/share/maven/repository + echo /usr/share/maven/repository fi @@ -1,45 +1,28 @@ #!/bin/bash -if [[ -z "$jh_cmd" ]]; then - export jh_cmd=$0 -fi -export jh_short=${jh_cmd##*/} - -if [[ -z "$JH_PATH" ]]; then +if [[ -z $JH_PATH ]]; then export JH_PATH=/usr/share/jh fi -usage() { - cmd="${1-$0}" - cmd="${cmd##*/jh-}" - file="$JH_PATH/jh-$cmd.help.txt" - if [[ -z "$cmd" ]]; then - echo "Usage: $jh_short <command> [command-specific-arguments]" - echo "Java helper for PKGBUILDs" - echo "" - "$jh_short" list-commands|sed 's/./ &/' - elif [[ -f "$JH_PATH/jh-$cmd.help.txt" ]]; then - sed "s|@cmd@|$jh_short|g" "$file" >> /dev/stderr - else - echo "$jh_short: Cannot find help file for '$cmd'" >> /dev/stderr - fi -} +if [[ -z $jh_short ]]; then + export jh_short=${0##*/} + export PATH="$JH_PATH:$PATH" +fi -run() { +main() { if [[ $# < 1 ]]; then - usage '' - exit 1; + jh-help >>/dev/stderr + return 1; fi cmd=$1 shift - file="$JH_PATH/jh-$cmd" - if [[ -x "$file" ]]; then - "$file" "$@" - exit $? + if [[ -x "$(which "jh-$cmd" 2>/dev/null)" ]]; then + "jh-$cmd" "$@" + return $? else echo "$jh_short: Cannot find command '$cmd'" >> /dev/stderr fi } -[[ "$jh_cmd" == "$0" ]] && run "$@" +main "$@" |