diff options
author | Mark Ferrell <major@homeonderanged.org> | 2014-04-14 09:47:01 -0700 |
---|---|---|
committer | Mark Ferrell <major@homeonderanged.org> | 2014-04-14 09:47:01 -0700 |
commit | 737163bef8f1ca026d543d7159153cb6691f0bcc (patch) | |
tree | dd0ee21674a6d82af767dd85169d57086e5e3ee8 | |
parent | 2b5b981498a178e1fa66a272b74ec2afd754ac29 (diff) |
Add a simple_usage() routine
* Added a simple_usage() routine to builders defaults to help sub-commands
that do not have options (outside of --help).
-rwxr-xr-x | build | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -19,6 +19,34 @@ error() { echo "error: $*" >&2; } # display the supplied <message> and exit with an error die() { error "$*"; exit 1; } +## simple_usage <cmd> <summary> +# A simplified usage interface for commands with no option arguments. +simple_usage() +{ + cmd="${1}" + summary="${2}" + shift 2 + + if test "$#" -eq '0'; then + error "no arguments to command" + echo "try 'build ${cmd} --help'" >&2 + exit 1 + fi + + while test "$#" -gt '0'; do + case "${1}" in + (-h|-help|--help) + echo "usage: build ${cmd} ${summary}" 2>&1 + exit 0;; + (--) shift; break;; + (-*) error "unknown option '${1}'" + echo "try 'build ${cmd} --help'" >&2 + exit 1;; + (*) break;; + esac + done +} + ## mkenv # prepare the environment structure for the current package mkenv() |