From 0074b6f1fbc8b0a550dd7f2461b993225249a9e3 Mon Sep 17 00:00:00 2001 From: James Pannacciulli Date: Wed, 29 Nov 2017 01:00:28 -0800 Subject: add support for specifying custom examples file or instantiated array name --- ariketa.sh | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'ariketa.sh') diff --git a/ariketa.sh b/ariketa.sh index 44b24ca..25df78f 100644 --- a/ariketa.sh +++ b/ariketa.sh @@ -10,9 +10,8 @@ _ariketa.dir () { printf "%s" "$_ariketa_dir" } - _ariketa.help () { - >&2 printf "%s\n" "$(&2 printf "%s\n" "$(<${ARIKETA_DIR:-.}${ARIKETA_DIR+/}USAGE)" return 1 } @@ -20,15 +19,38 @@ _sourced? () { [[ ${FUNCNAME[$(( ${#FUNCNAME[@]} - 1 ))]} == "source" ]] } +ARIKETA_DIR=$(_ariketa.dir) + _sourced? || { _ariketa.help exit $? } -ARIKETA_DIR=$(_ariketa.dir) +until [[ -z "$1" ]]; do + case "$1" in + -h|--help) + _ariketa.help + return $?;; + -a|--array) + # copy by indirection to set of discrete elements in named array + _ariketa_array_elements="${2:?Missing name parameter for '-a'}[@]" + _examples=( "${!_ariketa_array_elements}" ) + shift 2;; + *) + _ariketa_examples_file="${1}" + [[ -r "${_ariketa_examples_file}" ]] || { + _ariketa.help + return $? + } + shift;; + esac +done -# load examples array -source "${ARIKETA_DIR:?}/config/examples.sh" +# load examples array from file if array not passed / copied from args +[[ -z "${_ariketa_array_elements}" ]] && { + source "${_ariketa_examples_file:-${ARIKETA_DIR:?}/config/examples.sh}" +} +unset _ariketa_array_elements # if examples array has no content, bail with USAGE text (( ${#_examples[@]} )) || { -- cgit v1.2.3