refactor: improve bin/configure

This commit is contained in:
Mark Bailey 2024-10-26 19:52:09 -04:00
parent 6a5500797d
commit 9972351903

19
bin/configure vendored
View File

@ -4,16 +4,14 @@ set -euC
_venv() {
_py_version=${1:-3.12.0}
if command -v pyenv >/dev/null 2>&1; then
pyenv install $_py_version
pyenv shell $_py_version
if [ -d .venv ]; then
rm -rf .venv
fi
python -m venv ".venv"
else
echo "Please install pyenv"
fi
}
VENV_match=venv
@ -32,7 +30,7 @@ _freeze() {
if [ -d .venv ]; then
source .venv/bin/activate
mv requirements.txt requirements.txt.bak
pip freeze >requirements.txt
pip freeze > requirements.txt
else
echo "Please run 'bin/configure init' first"
fi
@ -48,14 +46,14 @@ _help() {
}
_check_cmds() {
if ! command -v pyenv >/dev/null 2>&1; then
if ! command -v pyenv >/dev/null; then
echo "Please install pyenv"
_fail=true
fi
}
_main() {
_fail=false
export _fail=false
_check_cmds
if $_fail; then
@ -63,13 +61,16 @@ _main() {
fi
_cmd="${1:-help}"
if ! [ -z "$_cmd" ]; then
shift
fi
case "$_cmd" in
--*) ;;
help | -h) _help ;;
"$VENV_match") _venv "${2:-}" ;;
"$VENV_match") _venv "$@" ;;
"$INIT_match")
_venv "${2:-}"
_venv "$@"
_init
;;
"$FREEZE_match") _freeze ;;