Skip to content

Commit

Permalink
Replace launcha with adminer command (#18)
Browse files Browse the repository at this point in the history
Looks good, passes test, thanks!
  • Loading branch information
mejta authored Oct 2, 2023
1 parent b143406 commit bc0c9f8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 76 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://<project>.ddev.site:9101`).
Then you can just `ddev adminer` or use `ddev describe` to get the URL (`https://<project>.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.**
52 changes: 52 additions & 0 deletions commands/host/adminer
Original file line number Diff line number Diff line change
@@ -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

76 changes: 3 additions & 73 deletions commands/host/launcha
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ project_files:
- adminer

global_files:
- commands/host/adminer
- commands/host/launcha
12 changes: 11 additions & 1 deletion tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bc0c9f8

Please sign in to comment.