bunbun.dev/start-server

38 lines
869 B
Plaintext
Raw Normal View History

2024-09-16 22:57:49 -07:00
#!/usr/bin/env bash
2024-05-20 22:00:35 -07:00
command="./main.fnl"
2024-05-20 22:00:35 -07:00
kill_command="pkill -f 'main\.fnl'"
log_file="log"
2024-09-16 22:57:49 -07:00
usage="Usage: start-server [options]
2024-05-20 22:00:35 -07:00
Options:
-h, --help Show this help message and exit
--localhost Run the server locally
2024-05-20 22:00:35 -07:00
-l, --log Log requests in the log file
--log-file Set the log file
-k, --kill Kill the server and exit
"
for (( i=1; i<=$#; i++ )); do
if [[ "${!i}" == "-h" || "${!i}" == "--help" ]]; then
printf "$usage"
exit 0
elif [[ "${!i}" == "--localhost" ]]; then
command="${command} --port 8080 --use-http"
2024-05-20 22:00:35 -07:00
elif [[ "${!i}" == "-l" || "${!i}" == "--log" ]]; then
command="${command} | tee ${log_file}"
elif [[ "${!i}" == "--log-file" ]]; then
((i++))
log_file="${!i}"
elif [[ "${!i}" == "-k" || "${!i}" == "--kill" ]]; then
eval "$kill_command"
exit 0
fi
done
2024-05-28 22:37:31 -07:00
$kill_command
2024-09-16 22:57:49 -07:00
eval "${command}"