refactor: add start command
This commit is contained in:
parent
dc72e69b95
commit
129802f290
39
bin/configure
vendored
39
bin/configure
vendored
@ -1,6 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -euC
|
set -euC
|
||||||
|
|
||||||
|
_activate_venv() {
|
||||||
|
. .venv/bin/activate
|
||||||
|
}
|
||||||
|
|
||||||
_venv() {
|
_venv() {
|
||||||
_py_version=${1:-3.12.0}
|
_py_version=${1:-3.12.0}
|
||||||
|
|
||||||
@ -17,7 +21,7 @@ VENV_match=venv
|
|||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
if [ -d .venv ]; then
|
if [ -d .venv ]; then
|
||||||
source .venv/bin/activate
|
_activate_venv
|
||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
else
|
else
|
||||||
@ -28,7 +32,7 @@ INIT_match=init
|
|||||||
|
|
||||||
_freeze() {
|
_freeze() {
|
||||||
if [ -d .venv ]; then
|
if [ -d .venv ]; then
|
||||||
source .venv/bin/activate
|
_activate_venv
|
||||||
mv requirements.txt requirements.txt.bak
|
mv requirements.txt requirements.txt.bak
|
||||||
pip freeze >requirements.txt
|
pip freeze >requirements.txt
|
||||||
else
|
else
|
||||||
@ -37,11 +41,32 @@ _freeze() {
|
|||||||
}
|
}
|
||||||
FREEZE_match=freeze
|
FREEZE_match=freeze
|
||||||
|
|
||||||
|
_start() {
|
||||||
|
_env=${1:-dev}
|
||||||
|
_port=${2:-8001}
|
||||||
|
_host=${3:-0.0.0.0}
|
||||||
|
|
||||||
|
case "$_env" in
|
||||||
|
dev) ;;
|
||||||
|
prod) _env=run ;;
|
||||||
|
*)
|
||||||
|
echo "Invalid environment: $_env"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
_activate_venv
|
||||||
|
|
||||||
|
fastapi $_env src/main.py --host $_host --port $_port
|
||||||
|
}
|
||||||
|
START_match=start
|
||||||
|
|
||||||
_help() {
|
_help() {
|
||||||
echo -e "Usage: $0 [help, -h | init {python_version} | venv {python_version} | freeze]\n"
|
echo -e "Usage: $0 [help, -h | venv | init | start | freeze]\n"
|
||||||
echo " help, -h: Show this help message"
|
echo " help, -h: Show this help message"
|
||||||
echo " init: Initialize virtual environment with {python_version} and install dependencies"
|
echo " venv \${python_version}: Create virtual environment with \${python_version}"
|
||||||
echo " venv: Create virtual environment with {python_version}"
|
echo " init \${python_version}: Initialize virtual environment with \${python_version} and install dependencies"
|
||||||
|
echo " start \${env(dev|prod):-dev} \${port:-8001} \${host:-0.0.0.0}: Start the application"
|
||||||
echo " freeze: Freeze dependencies"
|
echo " freeze: Freeze dependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +93,12 @@ _main() {
|
|||||||
case "$_cmd" in
|
case "$_cmd" in
|
||||||
--*) ;;
|
--*) ;;
|
||||||
help | -h) _help ;;
|
help | -h) _help ;;
|
||||||
|
"$START_match") _start "$@" ;;
|
||||||
"$VENV_match") _venv "$@" ;;
|
"$VENV_match") _venv "$@" ;;
|
||||||
"$INIT_match")
|
"$INIT_match")
|
||||||
_venv "$@"
|
_venv "$@"
|
||||||
_init
|
shift
|
||||||
|
_init "$@"
|
||||||
;;
|
;;
|
||||||
"$FREEZE_match") _freeze ;;
|
"$FREEZE_match") _freeze ;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
x
Reference in New Issue
Block a user