#!/bin/bash

OPTS=$@

# Add formatting plugin to the command for the +formatting variant, additionally to user provided plugins.
if [ -f /opt/local/share/java/detekt-cli/detekt-formatting.jar ]; then
    while [ $# -gt 0 ]; do
        case $1 in
            -p | --plugins)
                ADDITIONAL_PLUGINS=",$2"
                OPTS=${OPTS/$1/}
                OPTS=${OPTS/$2/}
                ;;
        esac
        shift
    done

    PLUGINOPTS="--plugins /opt/local/share/java/detekt-cli/detekt-formatting.jar$ADDITIONAL_PLUGINS"
fi

java -cp /opt/local/share/java/detekt-cli/detekt-cli.jar io.gitlab.arturbosch.detekt.cli.Main $PLUGINOPTS $OPTS
