Commit 522b16f1 authored by rhpvorderman's avatar rhpvorderman

Edited .scalafmt.conf typo

parent 6204f3ad
# For some odd reason the `scalafmt` is not executable when installed
# with brew. This line does the trick.
chmod u+x bin/scalafmt
#!/bin/sh
java -jar PATH_TO/scalafmt.jar $@
java -jar PATH_TO\scalafmt.jar %*
#!//usr/bin/env bash
check_binary(){
command -v "$0" >/dev/null 2>&1 || { echo >&2 "Missing dependency $0, exiting."; exit 1; }
}
# I'm not sure if this would have portability issues...
check_version(){
if [[ $1 = $2 ]]; then
echo $1;
else
echo -e "$1\n$2" | sort -nr | head -1
fi
}
CURL=$(which curl)
TAR=$(which tar)
JAVA=$(which java)
GREP=$(which grep)
CUT=$(which cut)
check_binary "$CURL"
check_binary "$TAR"
check_binary "$JAVA"
check_binary "$GREP"
check_latest () {
echo "Checking latest version from github..."
latest_version=$($CURL -s https://api.github.com/repos/scalameta/scalafmt/releases/latest | $GREP -Eo '"tag_name":(.*)' | $CUT -d \" -f 4)
if [[ $latest_version = "" ]]; then
echo "The github call failed, either because of an internet connection issue or rate limits..."
exit 1
fi
}
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
version_file="$HOME/.scalafmt-bin/version"
upgrade=false
if [[ -e $version_file ]]; then
latest_version=$(cat $version_file)
scalafmt_version=$latest_version
fi
print_usage (){
echo -e "scalafmt runner verson: 0.1.1"
echo -e "Usage: ./scalafmt [RUNNER OPTS] [SCALAFMT OPTS]"
echo -e "--version [VERSION] \t Version to invoke for scalafmt (fmt: 0.4.2, not v0.4.2)"
echo -e "--dir [DIR] \t\t Directory to store scalafmt jars, default is $HOME/.scalafmt-bin/"
echo -e "--upgrade \t\t Check GitHub for the latest version of scalafmt and use that"
echo -e "--h \t\t\t Display this message, this must be the first arguement for this to be invoked"
echo
echo -e "This script only checks the first three args for it's options, anything beyond that is ignored"
echo -e "and will probably cause scalafmt to produce an error since these are not options in scalafmt's runtime"
exit 0;
}
# We check all 3 now because it's possible to pass upgrade in and then
# pass a custom directory in. You can't pass all the args in, you have to choose
# specifying a version or upgrading to the latest from github.
if [[ "$1" = "--h" ]]; then
print_usage
fi
for arg in "$1" "$2" "$3"; do
case "$arg" in
--version)
if [[ $upgrade = true || $3 = "--upgrade" ]]; then
echo "You can't specify a custom version with --upgrade"
exit 1
fi
if [[ $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
scalafmt_version="v$2"
echo "Using version: $scalafmt_version"
shift 2
else
echo "You must pass a valid version with --v"
exit 1
fi
;;
--dir)
echo "Using dir: $2"
default_dir="$2"
shift 2
;;
--upgrade)
if [[ $2 = "--version" ]]; then
echo "You can't specify a custom version with --upgrade"
exit 1
fi
upgrade=true
check_latest
scalafmt_version=$latest_version
shift
;;
*)
;;
esac
done
if [[ ! -e $version_file && $upgrade = false && -z $scalafmt_version ]]; then
echo "No version file, checking for latest..."
check_latest
echo "Setting latest version to: $latest_version"
scalafmt_version=$latest_version
fi
if [[ ! "$default_dir" ]]; then
default_dir="$HOME/.scalafmt-bin/releases/$scalafmt_version"
fi
if [[ ! -d "$default_dir" ]]; then
echo "$default_dir does not exist, creating it..."
mkdir -p "$default_dir"
fi
echo $(check_version "$scalafmt_version" "$latest_version") > $version_file
scala_version="2.11"
scalafmt_filename="scalafmt-$scalafmt_version.jar"
scalafmt_repo="https://github.com/scalameta/scalafmt/releases/download/$scalafmt_version/scalafmt.tar.gz"
set -e
if [[ ! -e "$default_dir/scalafmt-$scalafmt_version.jar" ]]; then
echo "No scalafmt jar for version $scalafmt_version, downloading it..."
echo "From: $scalafmt_repo"
$CURL --progress -L "$scalafmt_repo" -o "$default_dir/scalafmt.tar.gz"
$TAR -xzf "$default_dir/scalafmt.tar.gz" -O "cli/target/scala-$scala_version/scalafmt.jar" > "$default_dir/$scalafmt_filename"
rm "$default_dir/scalafmt.tar.gz"
fi
$JAVA -jar "$default_dir/$scalafmt_filename" "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment