Add shfmt config

This commit is contained in:
Andreas Zweili 2023-08-27 14:47:44 +02:00
parent 45a2d9ed22
commit 9fcb2a1a39
2 changed files with 21 additions and 21 deletions

3
.editorconfig Normal file
View File

@ -0,0 +1,3 @@
[*.sh]
indent_style = space
indent_size = 4

39
dev.sh
View File

@ -2,12 +2,12 @@
# Helper functions not exposed to the user { # Helper functions not exposed to the user {
# Load example data # Load example data
_init () { _init() {
python ./src/manage.py loaddata src/network_inventory.yaml python ./src/manage.py loaddata src/network_inventory.yaml
} }
# Setup the database # Setup the database
_setup () { _setup() {
overmind start -l db -D overmind start -l db -D
if [ -f .direnv/first_run ]; then if [ -f .direnv/first_run ]; then
sleep 2 sleep 2
@ -41,15 +41,15 @@ _setup () {
sleep 2 sleep 2
} }
_open_url () { _open_url() {
if [[ ! -z "${DEFAULT_BROWSER}" ]]; then if [[ ! -z "${DEFAULT_BROWSER}" ]]; then
$DEFAULT_BROWSER $url $DEFAULT_BROWSER $url
elif type explorer.exe &> /dev/null; then elif type explorer.exe &>/dev/null; then
explorer.exe $url explorer.exe $url
fi fi
} }
_create_url () { _create_url() {
if [ -f /etc/wsl.conf ]; then if [ -f /etc/wsl.conf ]; then
echo "http://localhost:$WEBPORT" echo "http://localhost:$WEBPORT"
else else
@ -62,7 +62,7 @@ _create_url () {
declare -A tasks declare -A tasks
declare -A descriptions declare -A descriptions
run () { run() {
_setup _setup
find . -name __pycache__ -o -name "*.pyc" -delete find . -name __pycache__ -o -name "*.pyc" -delete
url=$(_create_url) url=$(_create_url)
@ -76,25 +76,25 @@ tasks["run"]=run
descriptions["start"]="Alias for run." descriptions["start"]="Alias for run."
tasks["start"]=run tasks["start"]=run
stop () { stop() {
overmind quit overmind quit
} }
descriptions["stop"]="Stop the webserver and DB." descriptions["stop"]="Stop the webserver and DB."
tasks["stop"]=stop tasks["stop"]=stop
venv () { venv() {
nix build .#venv -o .venv nix build .#venv -o .venv
} }
descriptions["venv"]="Build a pseudo venv that editors like VS Code can use." descriptions["venv"]="Build a pseudo venv that editors like VS Code can use."
tasks["venv"]=venv tasks["venv"]=venv
build-container (){ build-container() {
nix build && docker load < result && docker run --rm -ti network-inventory:latest nix build && docker load <result && docker run --rm -ti network-inventory:latest
} }
descriptions["build-container"]="Build and load OCI container." descriptions["build-container"]="Build and load OCI container."
tasks["build-container"]=build-container tasks["build-container"]=build-container
clean () { clean() {
find . \( -name __pycache__ -o -name "*.pyc" \) -delete find . \( -name __pycache__ -o -name "*.pyc" \) -delete
rm -rf htmlcov/ rm -rf htmlcov/
rm -f .direnv/first_run rm -f .direnv/first_run
@ -104,34 +104,32 @@ clean () {
descriptions["clean"]="Reset the project to a fresh state including the database." descriptions["clean"]="Reset the project to a fresh state including the database."
tasks["clean"]=clean tasks["clean"]=clean
cleanall() {
cleanall () {
git clean -xdf git clean -xdf
} }
descriptions["cleanall"]="Completly remove any files which are not checked into git." descriptions["cleanall"]="Completly remove any files which are not checked into git."
tasks["cleanall"]=cleanall tasks["cleanall"]=cleanall
debug () { debug() {
pytest --pdb --nomigrations --cov=. --cov-report=html ./src/ pytest --pdb --nomigrations --cov=. --cov-report=html ./src/
} }
descriptions["debug"]="Run the tests and drop into the debugger on failure." descriptions["debug"]="Run the tests and drop into the debugger on failure."
tasks["debug"]=debug tasks["debug"]=debug
check (){ check() {
nix flake check nix flake check
} }
descriptions["check"]="Run the linter and tests." descriptions["check"]="Run the linter and tests."
tasks["check"]=check tasks["check"]=check
test() {
test (){
export DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test export DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test
pytest -nauto --nomigrations --cov-config="$PROJECT_DIR/.coveragerc" --cov-report=html "$PROJECT_DIR/src" pytest -nauto --nomigrations --cov-config="$PROJECT_DIR/.coveragerc" --cov-report=html "$PROJECT_DIR/src"
} }
descriptions["test"]="Run the tests in the RAM DB and write a coverage report." descriptions["test"]="Run the tests in the RAM DB and write a coverage report."
tasks["test"]=test tasks["test"]=test
update (){ update() {
pdm update pdm update
} }
descriptions["update"]="Update the dependencies." descriptions["update"]="Update the dependencies."
@ -140,14 +138,13 @@ tasks["update"]=update
# only one task at a time # only one task at a time
if [ $# != 1 ]; then if [ $# != 1 ]; then
printf "usage: dev <task_name>\n\n" printf "usage: dev <task_name>\n\n"
for task in "${!tasks[@]}" for task in "${!tasks[@]}"; do
do
echo "$task - ${descriptions[$task]}" echo "$task - ${descriptions[$task]}"
done done
else else
# Check if task is available # Check if task is available
if [[ -v "tasks[$1]" ]] ; then if [[ -v "tasks[$1]" ]]; then
${tasks["$1"]} ${tasks["$1"]}
else else
echo "Task not found." echo "Task not found."