Skip to content

Commit

Permalink
Merge pull request #56 from ashcrow/rhcos-toolbox-add-help-switch
Browse files Browse the repository at this point in the history
rhcos-toolbox: Add help switch
  • Loading branch information
yuqi-zhang committed May 21, 2019
2 parents aae6c4f + 273424d commit a529538
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions rhcos-toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ set -eo pipefail

trap cleanup EXIT

setup() {
REGISTRY=registry.redhat.io
IMAGE=rhel8/support-tools
TOOLBOX_NAME=toolbox-"${USER}"
# Defaults
REGISTRY=registry.redhat.io
IMAGE=rhel8/support-tools
TOOLBOX_NAME=toolbox-"${USER}"
TOOLBOXRC="${HOME}"/.toolboxrc

setup() {
# Allow user overrides

toolboxrc="${HOME}"/.toolboxrc
if [ -f "${toolboxrc}" ]; then
if [ -f "${TOOLBOXRC}" ]; then
echo ".toolboxrc file detected, overriding defaults..."
source "${toolboxrc}"
source "${TOOLBOXRC}"
fi
TOOLBOX_IMAGE="${REGISTRY}"/"${IMAGE}"
}
Expand Down Expand Up @@ -122,8 +122,34 @@ container_exec() {
"$@"
}

show_help() {
echo "USAGE: toolbox [-h/--help] [command]
toolbox is a small script that launches a container to let you bring in your favorite debugging or admin tools.
The toolbox container is a pet container and will be restarted on following runs.
To remove the container and start fresh, do sudo podman rm ${TOOLBOX_NAME}.
Options:
-h/--help: Shows this help message
You may override the following variables by setting them in ${TOOLBOXRC}:
- REGISTRY: The registry to pull from. Default: $REGISTRY
- IMAGE: The image and tag from the registry to pull. Default: $IMAGE
- TOOLBOX_NAME: The name to use for the local container. Default: $TOOLBOX_NAME
Example toolboxrc:
REGISTRY=my.special.registry.example.com
IMAGE=debug:latest
TOOLBOX_NAME=special-debug-container"
}

main() {
# Execute setup first so we get proper variables
setup
# If we are passed a help switch, show help and exit
if [[ "$1" =~ ^(--help|-h)$ ]]; then
show_help
exit 0
fi
run "$@"
cleanup
}
Expand Down

0 comments on commit a529538

Please sign in to comment.