#!/usr/bin/env bash

# Exit immediately if a command exits with a non-zero status
set -e

fix_mode=false
for arg in "$@"; do
  case $arg in
    --fix)
      fix_mode=true
      shift
      ;;
  esac
done

# Run all linters using a single call to run_in_container
echo "Running linters..."
if [ "$fix_mode" = true ]; then
  echo "Fixing issues automatically..."
  bash ./run_in_container bash -c "ruff format . $ruff_args && ruff check --fix --extend-select I --unsafe-fixes . $ruff_args"
else
  echo "Checking format and code style..."
  bash ./run_in_container bash -c "ruff format --diff . $ruff_args ; format_code=\$? ; ruff check --extend-select I . $ruff_args ; check_code=\$? ; exit \$(( format_code || check_code ))"
fi
