123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/bin/bash
-
- FFOOD_DATA_DIR=${FFOOD_DATA_DIR:-$HOME/.ffood}
- FFOOD_DIR=${FFOOD_DIR:-__FFOOD_DIR__}
- FFOOD_ARTIFACTS_DIR=${FFOOD_ARTIFACTS_DIR:-artifacts}
- FFOOD_DEBUG=${FFOOD_DEBUG:-false}
- FFOOD_DEBUGINIT=${FFOOD_DEBUGINIT:-false}
- FFOOD_INCLUDE=${FFOOD_INCLUDE:-$FFOOD_DIR/include}
- FFOOD_MKPRETTY=${FFOOD_MKPRETTY:-plain}
- FFOOD_VERBOSE=${FFOOD_VERBOSE:-false}
- FFOOD_VERSION=__VERSION__
-
- ffood() {
- case $1 in
- __debug)
- $FFOOD_DEBUGINIT || return 0
- shift
- echo "debug: $@" >&2
- ;;
- __die)
- shift
- echo "$@" >&2
- exit 1
- ;;
- doc)
- ffood __die "not implemented (sorry...)"
- ;;
- import)
- ffood __debug "importing module $2"
- local mfile=$(ffood _list_mfiles_like $2 | head -1)
- test -n "$mfile" || ffood __die "cannot find module $2"
- ffood __debug "found module file: $mfile"
- . $mfile
- return $?
- ;;
- _list_all_functions)
- local mfile
- ffood _list_all_mfiles | while read mfile;
- do
- ffood _list_functions_in_mfile "$mfile"
- done
- ;;
- _list_all_modules)
- local mp mfn;
- ffood _list_all_mfiles | while read mp;
- do
- mfn="${mp##*/}"
- echo "${mfn%%.sh}"
- done
- ;;
- _list_all_mfiles)
- {
- echo $FFOOD_INCLUDE/*.sh | tr ' ' '\n'
- test -n "$FFOOD_PATH" && echo $FFOOD_PATH/*.sh
- } | tr ' ' '\n'
- ;;
- _list_mfiles_like)
- test -f "$FFOOD_INCLUDE/$2.sh" && echo "$FFOOD_INCLUDE/$2.sh"
- test -n "$FFOOD_PATH" -a -f "$FFOOD_PATH/$2.sh" && echo "$FFOOD_PATH/$2.sh"
- ;;
- _list_functions_in_mfile)
- local mfile="$2"
- grep -HE '^[[:alnum:]_]+\(\) \{' "$mfile" \
- | sed -e 's/^.*\///; s/\.sh:/./; s/(.*//'
- ;;
- *)
- ffood __die "unknown ffood command: $1"
- ;;
- esac
- }
-
- ffood __debug "FFOOD_DATA_DIR='$FFOOD_DATA_DIR'"
- ffood __debug "FFOOD_DIR='$FFOOD_DIR'"
- ffood __debug "FFOOD_ARTIFACTS_DIR='$FFOOD_ARTIFACTS_DIR'"
- ffood __debug "FFOOD_DEBUG='$FFOOD_DEBUG'"
- ffood __debug "FFOOD_DEBUGINIT='$FFOOD_DEBUGINIT'"
- ffood __debug "FFOOD_INCLUDE='$FFOOD_INCLUDE'"
- ffood __debug "FFOOD_INIPATH='$FFOOD_INIPATH'"
- ffood __debug "FFOOD_MKPRETTY='$FFOOD_MKPRETTY'"
- ffood __debug "FFOOD_VERBOSE='$FFOOD_VERBOSE'"
- ffood __debug "FFOOD_VERSION='$FFOOD_VERSION'"
|