#!/bin/bash

_help() {
cat <<EOF
Usage: ./build.sh [-h|-t|-b|-r]
	h Help    : shows this command
	t Test    : Runs All tests from cargo tests to client tests
	b Build   : Builds dev build with 'cargo build'
	r Release : Builds release build with --release flag
EOF
}

[[ -z $1  ]] && _help && exit 0

while getopts ":htbr" arg; do
	case ${arg} in
		h)echo help command;;
		t)
			cargo build 1>/dev/null 2>&1
			cargo test  1>/dev/null 2>&1
			cargo run -- -s  &
			server=$!
			echo Waiting on server to spin up && sleep 2

			export CARGO_BIN=$HOME/.cargo/bin/cargo
			python3 client-tests/client.py
			kill -9 $server
			;;
		b)cargo build;;
		r)cargo build --release;;
		*) _help;;
	esac
done
