functions

This commit is contained in:
Marc Beninca 2024-08-25 21:21:09 +02:00
parent b6eb01bb34
commit c84480bc82
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -169,6 +169,99 @@ spcd_step_wipe() {
"SPCD_STEP_${SPCD_STEP_LEVEL}_LABEL"
}
# ╭───────────┬───────╮
# │ functions │ error │
# ╰───────────┴───────╯
spcd_error_ci() {
echo "× CI: ${*}"
exit "${SPCD_ERROR_CI}"
}
spcd_error_os() {
spcd_error_os__variable="${1}"
printf "× OS: "
spcd_echo "${spcd_error_os__variable}"
exit "${SPCD_ERROR_OS}"
}
# ╭───────────┬─────╮
# │ functions │ git │
# ╰───────────┴─────╯
spcd_git_clone() {
if [ -n "${1}" ]; then
spcd_gc__name="$(basename "${1}")"
spcd_gc__path="${SPCD_DL}/${spcd_gc__name}"
spcd_gc__url="$(spcd_git_url "${1}")"
git clone "${spcd_gc__url}" "${spcd_gc__path}"
echo "${spcd_gc__path}"
fi
}
spcd_git_url() {
if [ -n "${1}" ]; then
case "${1}" in
http*) echo "${1}" ;;
*/*) echo "${SPCD_PROJECT_ROOT}/${1}" ;;
*) echo "${SPCD_PROJECT_ROOT}/${SPCD_PROJECT_PATH}/${1}" ;;
esac
fi
}
# ╭───────────┬────╮
# │ functions │ os │
# ╰───────────┴────╯
spcd_os_grep() {
spcd_os_grep__variable="${1}"
[ -n "${spcd_os_grep__variable}" ] &&
grep "^${spcd_os_grep__variable}=" "/etc/os-release" |
sed "s|^${spcd_os_grep__variable}=||" |
sed "s|^\"\(.*\)\"$|\1|"
}
spcd_os_mkdir() {
spcd_os_mkdir__path="${1}"
if [ -n "${spcd_os_mkdir__path}" ]; then
echo "${spcd_os_mkdir__path}"
mkdir --parents "${spcd_os_mkdir__path}"
fi
}
spcd_os_rm() {
spcd_os_rm__path="${1}"
if [ -e "${spcd_os_rm__path}" ]; then
echo "${spcd_os_rm__path}"
rm -r "${spcd_os_rm__path}" || exit
fi
}
# ╭───────────┬──────╮
# │ functions │ step │
# ╰───────────┴──────╯
spcd_step() {
if [ -n "${1}" ]; then
spcd_step__prefix="SPCD_STEP_${SPCD_STEP_LEVEL}"
spcd_step__index="${spcd_step__prefix}_INDEX"
eval "${spcd_step__index}=\$((${spcd_step__index} + 1))"
eval "${spcd_step__prefix}_LABEL=\"${1}\""
spcd_banner_render
fi
}
spcd_step_in() {
[ -n "${1}" ] && spcd_step "${1}"
SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL + 1))
spcd_step_wipe
}
spcd_step_out() {
spcd_step_wipe
SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL - 1))
}
# ╭───────┬─────╮
# │ steps │ env │
# ╰───────┴─────╯
@ -979,99 +1072,6 @@ ${SPCD_PYTHON_ALIAS} / ${spcd_stp__name}"
"${SPCD_PYTHON_ALIAS}" -m "${spcd_stp__name}"
}
# ╭───────────┬───────╮
# │ functions │ error │
# ╰───────────┴───────╯
spcd_error_ci() {
echo "× CI: ${*}"
exit "${SPCD_ERROR_CI}"
}
spcd_error_os() {
spcd_error_os__variable="${1}"
printf "× OS: "
spcd_echo "${spcd_error_os__variable}"
exit "${SPCD_ERROR_OS}"
}
# ╭───────────┬─────╮
# │ functions │ git │
# ╰───────────┴─────╯
spcd_git_clone() {
if [ -n "${1}" ]; then
spcd_gc__name="$(basename "${1}")"
spcd_gc__path="${SPCD_DL}/${spcd_gc__name}"
spcd_gc__url="$(spcd_git_url "${1}")"
git clone "${spcd_gc__url}" "${spcd_gc__path}"
echo "${spcd_gc__path}"
fi
}
spcd_git_url() {
if [ -n "${1}" ]; then
case "${1}" in
http*) echo "${1}" ;;
*/*) echo "${SPCD_PROJECT_ROOT}/${1}" ;;
*) echo "${SPCD_PROJECT_ROOT}/${SPCD_PROJECT_PATH}/${1}" ;;
esac
fi
}
# ╭───────────┬────╮
# │ functions │ os │
# ╰───────────┴────╯
spcd_os_grep() {
spcd_os_grep__variable="${1}"
[ -n "${spcd_os_grep__variable}" ] &&
grep "^${spcd_os_grep__variable}=" "/etc/os-release" |
sed "s|^${spcd_os_grep__variable}=||" |
sed "s|^\"\(.*\)\"$|\1|"
}
spcd_os_mkdir() {
spcd_os_mkdir__path="${1}"
if [ -n "${spcd_os_mkdir__path}" ]; then
echo "${spcd_os_mkdir__path}"
mkdir --parents "${spcd_os_mkdir__path}"
fi
}
spcd_os_rm() {
spcd_os_rm__path="${1}"
if [ -e "${spcd_os_rm__path}" ]; then
echo "${spcd_os_rm__path}"
rm -r "${spcd_os_rm__path}" || exit
fi
}
# ╭───────────┬──────╮
# │ functions │ step │
# ╰───────────┴──────╯
spcd_step() {
if [ -n "${1}" ]; then
spcd_step__prefix="SPCD_STEP_${SPCD_STEP_LEVEL}"
spcd_step__index="${spcd_step__prefix}_INDEX"
eval "${spcd_step__index}=\$((${spcd_step__index} + 1))"
eval "${spcd_step__prefix}_LABEL=\"${1}\""
spcd_banner_render
fi
}
spcd_step_in() {
[ -n "${1}" ] && spcd_step "${1}"
SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL + 1))
spcd_step_wipe
}
spcd_step_out() {
spcd_step_wipe
SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL - 1))
}
# ╭───────────╮
# │ functions │
# ╰───────────╯