From bc0c9f8b0982e00d4da0719cd07bca71edf2f2ac Mon Sep 17 00:00:00 2001 From: Daniel Mejta Date: Mon, 2 Oct 2023 11:31:12 +0200 Subject: [PATCH] Replace `launcha` with `adminer` command (#18) Looks good, passes test, thanks! --- README.md | 3 +- commands/host/adminer | 52 +++++++++++++++++++++++++++++ commands/host/launcha | 76 ++----------------------------------------- install.yaml | 1 + tests/test.bats | 12 ++++++- 5 files changed, 68 insertions(+), 76 deletions(-) create mode 100755 commands/host/adminer diff --git a/README.md b/README.md index 5f1bfc4..b4b3b0c 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,11 @@ This currently supports: * `ddev get ddev/ddev-adminer && ddev restart` -Then you can just `ddev launcha -a` or use `ddev describe` to get the URL (`https://.ddev.site:9101`). +Then you can just `ddev adminer` or use `ddev describe` to get the URL (`https://.ddev.site:9101`). ## What does this add-on do? * Adds the adminer container as a service -* Adds a `ddev launcha` command at the project level with a `ddev launcha -a` (or `ddev launcha --adminer`) option to launch you right into adminer. **Contributed by [@bserem](https://github.com/bserem).** **Maintained by DDEV team.** diff --git a/commands/host/adminer b/commands/host/adminer new file mode 100755 index 0000000..f40b9a5 --- /dev/null +++ b/commands/host/adminer @@ -0,0 +1,52 @@ +#!/bin/bash + +## #ddev-generated: If you want to edit and own this file, remove this line. +## Description: Launch a browser with Adminer +## Usage: adminer +## Example: "ddev adminer" + +DDEV_ADMINER_PORT=9100 +DDEV_ADMINER_HTTPS_PORT=9101 + +FULLURL=${DDEV_PRIMARY_URL} +HTTPS="" +if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi + +if [[ ! -z "${GITPOD_INSTANCE_ID}" ]] || [[ "${CODESPACES}" == "true" ]]; then + FULLURL="${FULLURL/-${DDEV_HOST_WEBSERVER_PORT}/-${DDEV_ADMINER_PORT}}" +else + if [ "${HTTPS}" = "" ]; then + FULLURL="${FULLURL%:[0-9]*}:${DDEV_ADMINER_PORT}" + else + FULLURL="${FULLURL%:[0-9]*}:${DDEV_ADMINER_HTTPS_PORT}" + fi +fi + +if [ -n "${1:-}" ] ; then + if [[ ${1::1} != "/" ]] ; then + FULLURL="${FULLURL}/"; + fi + + FULLURL="${FULLURL}${1}"; +fi + +if [ "${DDEV_DEBUG:-}" = "true" ]; then + printf "FULLURL $FULLURL\n" && exit 0 +fi + +case $OSTYPE in + linux-gnu) + if [[ ! -z "${GITPOD_INSTANCE_ID}" ]]; then + gp preview ${FULLURL} + else + xdg-open ${FULLURL} + fi + ;; + "darwin"*) + open ${FULLURL} + ;; + "win*"* | "msys"*) + start ${FULLURL} + ;; +esac + diff --git a/commands/host/launcha b/commands/host/launcha index 4a6c90e..c62f58f 100755 --- a/commands/host/launcha +++ b/commands/host/launcha @@ -1,76 +1,6 @@ #!/bin/bash #ddev-generated -## Description: Launch a browser with the current site -## Usage: launcha [path] [-a|--adminer] [-p|--phpmyadmin] [-m|--mailhog] -## Example: "ddev launcha" or "ddev launcha /admin/reports/status/php" or "ddev launcha phpinfo.php", for Adminer "ddev launcha -a", MailHog "ddev launch -m" - -FULLURL=${DDEV_PRIMARY_URL} -HTTPS="" -if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi - -while :; do - case ${1:-} in - -h|-\?|--help) - show_help - exit - ;; - -a|--adminer) - if [ "${HTTPS}" = "" ]; then - FULLURL="${FULLURL%:[0-9]*}:9100" - else - FULLURL="${FULLURL%:[0-9]*}:9101" - fi - ;; - -p|--phpmyadmin) - if [ "${HTTPS}" = "" ]; then - FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_PORT}" - else - FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_HTTPS_PORT}" - fi - ;; - -m|--mailhog) - if [ "${HTTPS}" = "" ]; then - FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILHOG_PORT}" - else - FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILHOG_HTTPS_PORT}" - fi - ;; - - --) # End of all options. - shift - break - ;; - -?*) - printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2 - ;; - *) # Default case: No more options, so break out of the loop. - break - esac - - shift - done - -if [ -n "${1:-}" ] ; then - if [[ ${1::1} != "/" ]] ; then - FULLURL="${FULLURL}/"; - fi - - FULLURL="${FULLURL}${1}"; -fi - -if [ ! -z ${DDEV_DEBUG:-} ]; then - printf "FULLURL $FULLURL\n" && exit 0 -fi - -case $OSTYPE in - linux-gnu) - xdg-open ${FULLURL} - ;; - "darwin"*) - open ${FULLURL} - ;; - "win*"* | "msys"*) - start ${FULLURL} - ;; -esac +## Description: DEPRECATED, use "ddev adminer" instead. +printf "'ddev launcha' is no longer available. Use 'ddev launch' and 'ddev adminer' instead. See https://github.com/ddev/ddev-adminer" +exit 2 diff --git a/install.yaml b/install.yaml index 841b235..0d4e3cb 100644 --- a/install.yaml +++ b/install.yaml @@ -6,4 +6,5 @@ project_files: - adminer global_files: +- commands/host/adminer - commands/host/launcha diff --git a/tests/test.bats b/tests/test.bats index 4077209..710696e 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -23,7 +23,17 @@ teardown() { echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 ddev get ${DIR} (ddev restart >/dev/null || (echo "# ddev restart returned exit code=%?" >&3 && false)) - ddev help launcha | grep adminer >/dev/null + ddev help adminer | grep adminer >/dev/null + + # ddev launcha must return an error + (exit_status=0; (ddev launcha > /dev/null 2>&1) || exit_status=$?; echo $exit_status) | { + read exit_status + if [ $exit_status -eq 0 ]; then + echo "Test failed: ddev launcha exited with no error" + exit 2 + fi + } + # echo "# Trying curl -s -L -k https://${PROJNAME}.ddev.site:9101/" >&3 curl --fail -s -L -k https://${PROJNAME}.ddev.site:9101/ | grep 'document.querySelector.*auth.*db' >/dev/null }