#!/usr/bin/env bash

# Cause the script to exit if a single command fails
set -e  # o pipefail -v

EXCLUDE=${EXCLUDE:=".git,__pycache__,docs/source/conf.py,build,dist"}
IGNORE=${IGNORE:="C812,C813,C814,C815,C816,D100,D104,D200,D204,D205,D301,D400,D401,D402,D412,D413,DAR103,DAR203,E203,E731,E1101,S101,S311,W0221,W503,W504,WPS0,WPS110,WPS111,WPS2,WPS305,WPS420,WPS421,WPS430,WPS431,WPS433,WPS5,WPS6"}
LINE_LENGTH=${LINE_LENGTH:=79}
QUOTES=${QUOTES:="double"}
# @TODO: add `--jobs`

_run_args=""
while (( "$#" )); do
  case "$1" in
    -l|--line-length)
      LINE_LENGTH=$2
      shift 2
      ;;
    --exclude)
      EXCLUDE=$2
      shift 2
      ;;
    --ignore)
      IGNORE=$2
      shift 2
      ;;
    --quotes)
      QUOTES=$2
      shift 2
      ;;
    *)
      _run_args="${_run_args} $1"
      shift
      ;;
  esac
done


flake8 \
    --exclude="${EXCLUDE}" \
    --ignore "${IGNORE}" \
    --max-line-length "${LINE_LENGTH}" \
    --max-doc-length "${LINE_LENGTH}" \
    --inline-quotes "${QUOTES}" \
    --multiline-quotes "${QUOTES}" \
    --docstring-quotes "${QUOTES}" \
    "$@"
