[Build] Using switch-case instead of if-else
@@ -303,6 +303,15 @@ prompt_confirm() {
esac
}
+check_deploy() {
+ echo "Checking..."
+
+ # Prompt for confirmation if deploying outside Travis
+ if [[ -z "${TRAVIS}" || "${TRAVIS}" != true ]]; then
+ prompt_confirm "You are trying to deploy outside of Travis. Are you sure?" || exit 0
+ fi
+}
+
deploy() {
echo "Deploying..."
@@ -323,53 +332,69 @@ deploy() {
docker_commands push versioned
}
-if [ "$cmd" == "build" ]; then
+case "$cmd" in
+ "build")
build_commands
-elif [ "$cmd" == "build_agent" ]; then
+ ;;
+ "build_agent")
build_command agent
-elif [ "$cmd" == "build_backend" ]; then
+ ;;
+ "build_backend")
build_command backend
-elif [ "$cmd" == "build_cli" ]; then
+ ;;
+ "build_cli")
build_command cli
-elif [ "$cmd" == "build_dashboard" ]; then
+ ;;
+ "build_dashboard")
install_dashboard_deps
build_dashboard
bundle_static_assets
-elif [ "$cmd" == "build_tools" ]; then
+ ;;
+ "build_tools")
build_tools
-elif [ "$cmd" == "dashboard" ]; then
+ ;;
+ "dashboard")
install_dashboard_deps
test_dashboard
-elif [ "$cmd" == "dashboard-ci" ]; then
+ ;;
+ "dashboard-ci")
install_yarn
install_dashboard_deps
test_dashboard
./codecov.sh -t $CODECOV_TOKEN -cF javascript -s dashboard
-elif [ "$cmd" == "deploy" ]; then
- if [[ -z "${TRAVIS}" || "${TRAVIS}" != true ]]; then
- prompt_confirm "You are trying to deploy outside of Travis. Are you sure?" || exit 0
- fi
+ ;;
+ "deploy")
+ check_deploy
deploy
-elif [ "$cmd" == "deps" ]; then
+ ;;
+ "deps")
install_deps
-elif [ "$cmd" == "docker" ]; then
+ ;;
+ "docker")
docker_commands "${@:2}"
-elif [ "$cmd" == "e2e" ]; then
+ ;;
+ "e2e")
# Accepts specific test name. E.g.: ./build.sh e2e -run TestAgentKeepalives
build_commands
e2e_commands "${@:2}"
-elif [ "$cmd" == "lint" ]; then
+ ;;
+ "lint")
linter_commands
-elif [ "$cmd" == "none" ]; then
+ ;;
+ "none")
echo "noop"
-elif [ "$cmd" == "quality" ]; then
+ ;;
+ "quality")
linter_commands
unit_test_commands
-elif [ "$cmd" == "unit" ]; then
+ ;;
+ "unit")
unit_test_commands
-elif [ "$cmd" == "integration" ]; then
+ ;;
+ "integration")
integration_test_commands
-else
+ ;;
+ *)
install_deps
linter_commands
build_tools
@@ -377,4 +402,5 @@ else
integration_test_commands
build_commands
e2e_commands
-fi
+ ;;
+esac
