refactor: use a task: prefix for public functions

This commit is contained in:
Oliver Davies 2021-12-04 21:20:36 +00:00
parent 124f78a74c
commit f1cf2090a4

69
run
View file

@ -7,55 +7,54 @@ if [[ ! -t 1 ]]; then
TTY="-T" TTY="-T"
fi fi
DC="${DC:-exec}" function task:bash {
task:exec bash "${@}"
function bash {
exec bash "${@}"
} }
function ci:test { function task:ci:test {
lint:dockerfile task:lint:dockerfile
} }
function exec { function task:exec {
# Run any command in the php container. # Run any command in the php container.
_dc php "${@}" docker-compose exec php "${@}"
} }
function composer { function task:composer {
# Execute Composer commands. # Execute Composer commands.
exec composer "${@}" task:exec composer "${@}"
} }
function db:export { function task:db:export {
drush sql:dump \ task:drush sql:dump \
--gzip \ --gzip \
--result-file=/app/drupal.sql --result-file=/app/drupal.sql
} }
function drupal:install { function task:drupal:install {
# Install Drupal. # Install Drupal.
drush site:install -y --account-pass admin123 --existing-config task:drush site:install -y --account-pass admin123 --existing-config
} }
function drush { function task:drush {
# Execute Drush commands. # Execute Drush commands.
exec drush "${@}" task:exec drush "${@}"
} }
function frontend:console { function task:frontend:console {
docker-compose run --rm node docker-compose run --rm node
} }
function help { function task:help {
printf "%s <task> [args]\n\nTasks:\n" "${0}" printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n # Only show functions that have the "task:" prefix.
compgen -A function | sed -En 's/task:(.*)/\1/p' | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n" printf "\nExtended help:\n Each task has comments for general usage\n"
} }
function lint:dockerfile { function task:lint:dockerfile {
docker container run --rm -i \ docker container run --rm -i \
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \ -v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
hadolint/hadolint hadolint \ hadolint/hadolint hadolint \
@ -64,33 +63,29 @@ function lint:dockerfile {
"${@}" - < tools/docker/Dockerfile "${@}" - < tools/docker/Dockerfile
} }
function test:functional { function task:test:functional {
_run_tests --testsuite functional "${@}" run-tests --testsuite functional "${@}"
} }
function test:integration { function task:test:integration {
# Run integration tests. # Run integration tests.
_run_tests --testsuite kernel "${@}" run-tests --testsuite kernel "${@}"
} }
function test:quality { function task:test:quality {
# Run quality checks (code linting, static analysis, etc.). # Run quality checks (code linting, static analysis, etc.).
DC="run --no-deps" docker-compose run --no-deps php phpcs
exec phpcs docker-compose run --no-deps php phpstan "--memory-limit=256M"
exec phpstan "--memory-limit=256M"
} }
function test:unit { function task:test:unit {
# Run unit tests. # Run unit tests.
_run_tests --testsuite unit "${@}" run-tests --testsuite unit "${@}"
} }
function _dc { function run-tests {
docker-compose ${DC} ${TTY} "${@}" # Run PHPUnit tests.
docker-compose run php --user ${DOCKER_WEB_USER} php phpunit "${@}"
} }
function _run_tests { eval "task:${@:-help}"
_dc --user ${DOCKER_WEB_USER} php phpunit "${@}"
}
eval "${@:-help}"