<commit_before>#! /bin/bash

set -euo pipefail
IFS=$'\n\t'

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)

ALL=
COMMON_ARGS=
TAG=
USERNAME=joelnb
VERBOSE=

build_all_images() {
	while read -rd $'\0' imagedir; do \
		build_single_image "${imagedir}"; \
	done < <(find "${DIR}" -mindepth 1 -maxdepth 1 -not -name ".git" -type d -print0)
}

build_single_image() {
	local path="${1:-}"

	if [ -z "${path}" ]; then
		return 1
	fi

	local image_name=$(basename "${path}")

	eval docker build -t "${USERNAME}/${image_name}${TAG}" "${COMMON_ARGS}" "${path}"
}

usage() {
	cat <<EOF
usage: $(basename "$0") [DIRECTORY]

Build dockerfiles for testing.

ARGUMENTS:
   DIRECTORY    The directory containing the Dockerfile. Not required
                if -a is specified as then all directories in the same
                location as this script will be built.

OPTIONS:
   -a           Build all images.
   -h           Show this message.
   -n           Pass the '--no-cache' option to docker build.
   -t TAG       A tag to apply to the built image.
   -u USER      The username to name images under [default: ${USERNAME}]
   -V           Increase output verbosity.
EOF
	exit 1
}

while getopts "hant:u:V" OPTION; do
	case $OPTION in
		h)
			usage
			;;
		a)
			ALL=1
			;;
		n)
			COMMON_ARGS="${COMMON_ARGS} --no-cache"
			;;
		t)
			TAG=":$OPTARG"
			;;
		u)
			USERNAME=$OPTARG
			;;
		V)
			VERBOSE=1
			;;
		?)
			usage
			;;
	esac
done

shift $(($OPTIND - 1))

DIRECTORY="${1:-}"
if [ -z "${DIRECTORY}" ]; then
	[ -z "${ALL}" ] && usage
else
	shift
fi

if [ -z "${DIRECTORY}" ]; then
	build_all_images
else
	build_single_image "${DIRECTORY}"
fi
<commit_msg>Just build everything if no directories are specified<commit_after>#! /bin/bash

set -euo pipefail
IFS=$'\n\t'

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)

ALL=
COMMON_ARGS=
TAG=
USERNAME=joelnb
VERBOSE=

build_all_images() {
	while read -rd $'\0' imagedir; do \
		build_single_image "${imagedir}"; \
	done < <(find "${DIR}" -mindepth 1 -maxdepth 1 -not -name ".git" -type d -print0)
}

build_single_image() {
	local path="${1:-}"

	if [ -z "${path}" ]; then
		return 1
	fi

	local image_name=$(basename "${path}")

	eval docker build -t "${USERNAME}/${image_name}${TAG}" "${COMMON_ARGS}" "${path}"
}

usage() {
	cat <<EOF
usage: $(basename "$0") [DIRECTORY]

Build dockerfiles for testing.

ARGUMENTS:
   DIRECTORY    The directory containing the Dockerfile. If no directory
                is specified as then all directories in the same location
                as this script will be built.

OPTIONS:
   -h           Show this message.
   -n           Pass the '--no-cache' option to docker build.
   -t TAG       A tag to apply to the built image.
   -u USER      The username to name images under [default: ${USERNAME}]
   -V           Increase output verbosity.
EOF
	exit 1
}

while getopts "hnt:u:V" OPTION; do
	case $OPTION in
		h)
			usage
			;;
		n)
			COMMON_ARGS="${COMMON_ARGS} --no-cache"
			;;
		t)
			TAG=":$OPTARG"
			;;
		u)
			USERNAME=$OPTARG
			;;
		V)
			VERBOSE=1
			;;
		?)
			usage
			;;
	esac
done

shift $(($OPTIND - 1))

DIRECTORY="${1:-}"
[ -n "${DIRECTORY}" ] && shift

if [ -z "${DIRECTORY}" ]; then
	build_all_images
else
	build_single_image "${DIRECTORY}"
fi

{'fraction_non_alphanumeric': 0.15629788538155073, 'fraction_numerical': 0.007661661048115232, 'mean_word_length': 2.7006802721088436, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6548876', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1182, 'n_words': 365}