#!/bin/bash

set -e

GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

CARGO=${CARGO:-cargo}

function rust_add_component() {
  local name=$1

  echo -e "${GREEN}rustup component add ${name}${NC}"
  rustup component add ${name}
}

# cargo fmt
rust_add_component rustfmt-preview
${CARGO} fmt -- --version
${CARGO} fmt -- --check

echo

rust_add_component clippy-preview
${CARGO} clippy --version
${CARGO} clippy -- -Dwarnings

echo -e "${YELLOW}OK${NC}"
