skip php option

generating the PHP format file is now optional:
- if the PHP command is unavailable, the PHP format file is automatically skipped
- if the --skip-php option is provided, the PHP format file is always skipped
- if the --force-php option is provided, the PHP command line MUST exist
This commit is contained in:
Doug Bird 2018-06-12 17:13:24 -07:00
parent a6df8d5628
commit bdc2689beb
1 changed files with 39 additions and 13 deletions

View File

@ -12,16 +12,20 @@ ME_DIR="/$0"; ME_DIR=${ME_DIR%/*}; ME_DIR=${ME_DIR:-.}; ME_DIR=${ME_DIR#/}/; ME_
HELPER_DIR=$ME_DIR/helpers HELPER_DIR=$ME_DIR/helpers
# #
# read options and flags # parse options
# #
OPTION_STATUS=0
QUIET_MODE=0 QUIET_MODE=0
HELP_MODE=0 HELP_MODE=0
OPTION_STATUS=0 FORCE_PHP=0
SKIP_PHP=0
while getopts :?qhua-: arg; do { case $arg in while getopts :?qhua-: arg; do { case $arg in
q) QUIET_MODE=1;; q) QUIET_MODE=1;;
h|u|a) HELP_MODE=1;; h|u|a) HELP_MODE=1;;
-) LONG_OPTARG="${OPTARG#*=}"; case $OPTARG in -) LONG_OPTARG="${OPTARG#*=}"; case $OPTARG in
quiet) QUIET_MODE=1;; quiet) QUIET_MODE=1;;
force-php) FORCE_PHP=1;;
skip-php) SKIP_PHP=1;;
help|usage|about) HELP_MODE=1;; help|usage|about) HELP_MODE=1;;
*) >&2 echo "$ME_NAME: unrecognized long option --$OPTARG"; OPTION_STATUS=2;; *) >&2 echo "$ME_NAME: unrecognized long option --$OPTARG"; OPTION_STATUS=2;;
esac ;; esac ;;
@ -31,6 +35,14 @@ shift $((OPTIND-1)) # remove parsed options and args from $@ list
[ "$OPTION_STATUS" != "0" ] && { >&2 echo "$ME_NAME: (FATAL) one or more invalid options"; exit $OPTION_STATUS; } [ "$OPTION_STATUS" != "0" ] && { >&2 echo "$ME_NAME: (FATAL) one or more invalid options"; exit $OPTION_STATUS; }
[ -z "$@" ] || { >&2 echo "$ME_NAME: (FATAL) one or more unrecognized positional arguments ($@)"; exit 2; } [ -z "$@" ] || { >&2 echo "$ME_NAME: (FATAL) one or more unrecognized positional arguments ($@)"; exit 2; }
#
# --skip-php --force-php sanity check
#
if ( [ "$FORCE_PHP" = "1" ] && [ "$SKIP_PHP" = "1" ] ); then
>&2 echo "$ME_NAME: --skip-php cannot be used with --force-php"
exit 2
fi
# #
# display welcome message # display welcome message
# #
@ -50,11 +62,13 @@ fi
# #
if [ "$HELP_MODE" = "1" ]; then if [ "$HELP_MODE" = "1" ]; then
echo "usage:" echo "usage:"
echo " $ME_NAME [-h] | [-q]" echo " $ME_NAME [-h] | [-q][--skip-php]"
echo "" echo ""
echo "options:" echo "options:"
echo " -h,--help: Print a help message and exit." echo " -h,--help: Print a help message and exit."
echo " -q,--quiet: Print less messages." echo " -q,--quiet: Print less messages."
echo " --force-php: Creating the PHP format file is mandatory."
echo " --skip-php: Always skip creating the PHP format file."
exit 0 exit 0
fi fi
@ -62,15 +76,23 @@ fi
# enforce dependencies # enforce dependencies
# #
DEPENDENCY_STATUS=0 DEPENDENCY_STATUS=0
depcheck() { dep_cmd=$1; dep_label=$2 node -v > /dev/null 2>&1 || {
$dep_cmd > /dev/null 2>&1 || { >&2 echo "$ME_NAME: failed dependency check for 'node', command is missing or inaccessible"
>&2 echo "$ME_NAME: failed dependency check for '$dep_label', command is missing or inaccessible"
DEPENDENCY_STATUS=1 DEPENDENCY_STATUS=1
} } }
depcheck "nodex -v" "node" if [ "$SKIP_PHP" != "1" ]; then
depcheck "php -v" "php" php -v > /dev/null 2>&1 || {
if [ "$FORCE_PHP" = "1" ]; then
>&2 echo "$ME_NAME: failed dependency check for 'php', command is missing or inaccessible"
DEPENDENCY_STATUS=1
else
SKIP_PHP=1
>&2 echo "$ME_NAME: (NOTICE) skipping PHP format generation, 'php' command is missing or inaccessible"
fi
}
fi
if [ "$DEPENDENCY_STATUS" != "0" ]; then if [ "$DEPENDENCY_STATUS" != "0" ]; then
>&2 echo "$ME_NAME: (FATAL) one or more dependency checks failed" >&2 echo "$ME_NAME: (FATAL) one or more required dependency checks failed"
exit 1 exit 1
fi fi
@ -100,11 +122,15 @@ helper() { helper_file=$1; helper_label=$2
# execute the helpers # execute the helpers
# #
helper generate-tlds-csv.js "new 'tlds.csv'" helper generate-tlds-csv.js "new 'tlds.csv'"
helper generate-php-tld-enum.php "new PHP format files"
helper generate-js-tld-enum.js "new JavaScript format files" helper generate-js-tld-enum.js "new JavaScript format files"
helper generate-json-tld-enum.js "new JSON format files" helper generate-json-tld-enum.js "new JSON format files"
if [ "$SKIP_PHP" != "1" ]; then
helper generate-php-tld-enum.php "new PHP format files"
else
[ "$QUIET_MODE" = "0" ] && echo "$ME_NAME: (NOTICE) skipped PHP"
fi
echo "$ME_NAME: all formats updates were successful" echo "$ME_NAME: format updates were successful"