<commit_before>#
# deta
#
# Copyright (c) 2011-2014 <NAME>
#
# Distributed under the terms of the MIT License.
# Redistributions of files must retain the above copyright notice.
#
# @COPYRIGHT 2011-2014 <NAME> <<EMAIL>>
# @LICENSE   http://www.opensource.org/licenses/mit-license.php The MIT License
# @LINK      http://github.com/davidpersson/deta
#

# @FUNCTION: msg*
# @USAGE: <message> [replacement0..]
# @DESCRIPTION:
# Outputs status messages honoring QUIET flag.
msg()       { if [[ $QUIET != "y" ]];   then _msg ""     "$@"; fi }
msginfo()   { if [[ $VERBOSE != "n" ]]; then _msg ""     "$@"; fi }
msgok()     { if [[ $QUIET != "y" ]];   then _msg "ok"   "$@"; fi }
msgskip()   { if [[ $QUIET != "y" ]];   then _msg "skip" "$@"; fi }
msgdry()    { if [[ $QUIET != "y" ]];   then _msg "dry"  "$@"; fi }
msgwarn()   { _msg "warn" "$@" >&2; }
msgfail()   { _msg "fail" "$@" >&2; }

# @FUNCTION: _msg
# @USAGE: <status> <message> [replacement0..]
# @DESCRIPTION:
# Outputs status messages.
_msg() {
	local status=$1
	local message=$2
	shift 2

	local IFS=""
	printf "[\e[1;34m%s\e[0m] [%5s] \e[1;32m%s\e[0m\n" \
		"$(date +%T)" \
		"$status" \
		"$(printf "$message" $@)"
}

msginfo "Module %s loaded." "core"

# @FUNCTION: role
# @USAGE: <role>
# @DESCRIPTION:
# The magic role "THIS" will always be mapped using the current
# wnvironment context. For all other roles the user is prompted
# to select from the available environments.
role() {
	local role=$(echo $1 | tr '[:upper:]' '[:lower:]')

	if [[ $role == "this" ]]; then
		_env_to_role current $role
	else
		local avail=""

		set +o errexit
		for file in $(ls $CONFIG_PATH/*.env 2> /dev/null); do
			local avail+="$(basename -s '.env' $file) "
		done
		set -o errexit

		local PS3="Please select an env to map to role ${role}: "
		select env in $avail; do
			_env_to_role $env $role
			break
		done
	fi
	msgok "Using role %s." $role
}

# @FUNCTION: _env_to_role
# @USAGE: <env> <role>
# @DESCRIPTION:
# Maps an env (left) to role provided to this function (right).
_env_to_role() {
	local tmp=$(mktemp -t deta.XXX)

	perl -pe "s/^(.*)=/$(echo $2 | tr '[:lower:]' '[:upper:]')_\1=/g" ${CONFIG_PATH}/${1}.env > $tmp
	source $tmp
	msgok "Mapped env %s to role %s." $@

	rm $tmp
}

# @FUNCTION: dry
# @DESCRIPTION:
# Checks if dryrun is enabled and displays warning message.
dry() {
	if [[ $DRYRUN != "y" ]]; then
		msgwarn "Dry run is NOT enabled! Press STRG+C to abort."
		msg "Starting in 3 seconds."
		echo -n "  "
		for I in {1..3}; do
			echo -n '.'<commit_msg>Stricter regex for prefixing.<commit_after>#
# deta
#
# Copyright (c) 2011-2014 <NAME>
#
# Distributed under the terms of the MIT License.
# Redistributions of files must retain the above copyright notice.
#
# @COPYRIGHT 2011-2014 <NAME> <<EMAIL>>
# @LICENSE   http://www.opensource.org/licenses/mit-license.php The MIT License
# @LINK      http://github.com/davidpersson/deta
#

# @FUNCTION: msg*
# @USAGE: <message> [replacement0..]
# @DESCRIPTION:
# Outputs status messages honoring QUIET flag.
msg()       { if [[ $QUIET != "y" ]];   then _msg ""     "$@"; fi }
msginfo()   { if [[ $VERBOSE != "n" ]]; then _msg ""     "$@"; fi }
msgok()     { if [[ $QUIET != "y" ]];   then _msg "ok"   "$@"; fi }
msgskip()   { if [[ $QUIET != "y" ]];   then _msg "skip" "$@"; fi }
msgdry()    { if [[ $QUIET != "y" ]];   then _msg "dry"  "$@"; fi }
msgwarn()   { _msg "warn" "$@" >&2; }
msgfail()   { _msg "fail" "$@" >&2; }

# @FUNCTION: _msg
# @USAGE: <status> <message> [replacement0..]
# @DESCRIPTION:
# Outputs status messages.
_msg() {
	local status=$1
	local message=$2
	shift 2

	local IFS=""
	printf "[\e[1;34m%s\e[0m] [%5s] \e[1;32m%s\e[0m\n" \
		"$(date +%T)" \
		"$status" \
		"$(printf "$message" $@)"
}

msginfo "Module %s loaded." "core"

# @FUNCTION: role
# @USAGE: <role>
# @DESCRIPTION:
# The magic role "THIS" will always be mapped using the current
# wnvironment context. For all other roles the user is prompted
# to select from the available environments.
role() {
	local role=$(echo $1 | tr '[:upper:]' '[:lower:]')

	if [[ $role == "this" ]]; then
		_env_to_role current $role
	else
		local avail=""

		set +o errexit
		for file in $(ls $CONFIG_PATH/*.env 2> /dev/null); do
			local avail+="$(basename -s '.env' $file) "
		done
		set -o errexit

		local PS3="Please select an env to map to role ${role}: "
		select env in $avail; do
			_env_to_role $env $role
			break
		done
	fi
	msgok "Using role %s." $role
}

# @FUNCTION: _env_to_role
# @USAGE: <env> <role>
# @DESCRIPTION:
# Maps an env (left) to role provided to this function (right).
_env_to_role() {
	local tmp=$(mktemp -t deta.XXX)

	perl -pe "s/^([a-zA-Z0-9_]+)=/$(echo $2 | tr '[:lower:]' '[:upper:]')_\1=/g" ${CONFIG_PATH}/${1}.env > $tmp
	cat $tmp
	source $tmp
	msgok "Mapped env %s to role %s." $@

	rm $tmp
}

# @FUNCTION: dry
# @DESCRIPTION:
# Checks if dryrun is enabled and displays warning message.
dry() {
	if [[ $DRYRUN != "y" ]]; then
		msgwarn "Dry run is NOT enabled! Press STRG+C to abort."
		msg "Starting in 3 seconds."
		echo -n "  "
		for I in {1..3}; do
			echo -n '.'
{'fraction_non_alphanumeric': 0.19382740318458816, 'fraction_numerical': 0.01651267937880873, 'mean_word_length': 3.348717948717949, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '687335', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1971, 'n_words': 611}