Last active
May 8, 2017 16:02
-
-
Save SnuktheGreat/f555f44575b2d744e7ae4962d22e7cae to your computer and use it in GitHub Desktop.
Docker wrapper for cqlsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
CONTAINER="" | |
CQLSH=() | |
# Parse options | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case ${key} in | |
--help) | |
DISPLAY_HELP=true | |
;; | |
-c|--container) | |
CONTAINER="$2" | |
shift | |
;; | |
*) | |
CQLSH+=("$1") | |
;; | |
esac | |
shift # past argument or value | |
done | |
if [ "$DISPLAY_HELP" = true ]; then | |
SCRIPT_NAME="$( basename ${BASH_SOURCE[0]} )" | |
echo "$SCRIPT_NAME is a Docker wrapper for cqlsh. It adds the following option:" | |
echo " -c, --container Link the given container to this container, so you can connect using the host name." | |
echo | |
docker run -it --rm cassandra cqlsh --help | |
exit 0; | |
fi | |
if [ -n "$CONTAINER" ]; then | |
docker run -it --link ${CONTAINER} --rm cassandra cqlsh ${CONTAINER} ${CQLSH[@]} | |
else | |
docker run -it --net=host --rm cassandra cqlsh ${CQLSH[@]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this script to run cqlsh from the latest Cassandra Docker container. I find this more convenient than installing it using pip. It also comes with the added benefit of being able to connect to containers which are not port-mapped to the host. To do so it adds one option: