refactor: improve bin/configure

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

43
bin/configure vendored
View File

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