123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/bin/bash
-
- FFOO_DATA_DIR=${FFOO_DATA_DIR:-$HOME/.ffoo}
- FFOO_DIR=${FFOO_DIR:-__FFOO_DIR__}
- FFOO_ARTIFACTS_DIR=${FFOO_ARTIFACTS_DIR:-artifacts}
- FFOO_DEBUG=${FFOO_DEBUG:-false}
- FFOO_DEBUGINIT=${FFOO_DEBUGINIT:-false}
- FFOO_INCLUDE=${FFOO_INCLUDE:-$FFOO_DIR/include}
- FFOO_MKPRETTY=${FFOO_MKPRETTY:-plain}
- FFOO_VERBOSE=${FFOO_VERBOSE:-false}
- FFOO_VERSION=__VERSION__
-
- ffoo() {
- case $1 in
- __debug)
- $FFOO_DEBUGINIT || return 0
- shift
- echo "debug: $@" >&2
- ;;
- __die)
- shift
- echo "$@" >&2
- exit 1
- ;;
- doc)
- ffoo __die "not implemented (sorry...)"
- ;;
- import)
- ffoo __debug "importing module $2"
- local mfile=$(ffoo _list_mfiles_like $2 | head -1)
- test -n "$mfile" || ffoo __die "cannot find module $2"
- ffoo __debug "found module file: $mfile"
- . $mfile
- return $?
- ;;
- _list_all_functions)
- local mfile
- ffoo _list_all_mfiles | while read mfile;
- do
- ffoo _list_functions_in_mfile "$mfile"
- done
- ;;
- _list_all_modules)
- local mp mfn;
- ffoo _list_all_mfiles | while read mp;
- do
- mfn="${mp##*/}"
- echo "${mfn%%.sh}"
- done
- ;;
- _list_all_mfiles)
- {
- echo $FFOO_INCLUDE/*.sh | tr ' ' '\n'
- test -n "$FFOO_PATH" && echo $FFOO_PATH/*.sh
- } | tr ' ' '\n'
- ;;
- _list_mfiles_like)
- test -f "$FFOO_INCLUDE/$2.sh" && echo "$FFOO_INCLUDE/$2.sh"
- test -n "$FFOO_PATH" -a -f "$FFOO_PATH/$2.sh" && echo "$FFOO_PATH/$2.sh"
- ;;
- _list_functions_in_mfile)
- local mfile="$2"
- grep -HE '^[[:alnum:]_]+\(\) \{' "$mfile" \
- | sed -e 's/^.*\///; s/\.sh:/./; s/(.*//'
- ;;
- *)
- ffoo __die "unknown ffoo command: $1"
- ;;
- esac
- }
-
- ffoo __debug "FFOO_DATA_DIR='$FFOO_DATA_DIR'"
- ffoo __debug "FFOO_DIR='$FFOO_DIR'"
- ffoo __debug "FFOO_ARTIFACTS_DIR='$FFOO_ARTIFACTS_DIR'"
- ffoo __debug "FFOO_DEBUG='$FFOO_DEBUG'"
- ffoo __debug "FFOO_DEBUGINIT='$FFOO_DEBUGINIT'"
- ffoo __debug "FFOO_INCLUDE='$FFOO_INCLUDE'"
- ffoo __debug "FFOO_INIPATH='$FFOO_INIPATH'"
- ffoo __debug "FFOO_MKPRETTY='$FFOO_MKPRETTY'"
- ffoo __debug "FFOO_VERBOSE='$FFOO_VERBOSE'"
- ffoo __debug "FFOO_VERSION='$FFOO_VERSION'"
|