#!/bin/zsh               
use scwrypts/environment-files
#####################################################################

MAIN() {
	PROMPT 'choose an environment to delete'
	ENV_NAME=$(SCWRYPTS__SELECT_ENV)
	[ ! $ENV_NAME ] && ABORT
	
	ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME))
	
	STATUS "preparing to remove '$ENV_NAME'"
	
	WARNING "
		the '$ENV_NAME' environment will be removed configured options
		and stored credentials will be lost forever:
	
		$(echo $ENV_FILES | sed 's| /|\n - /|g; s/^/ - /')
	 "
	
	yN 'continue?' || ABORT
	
	STATUS "removing environment"
	for ENV_FILE in ${ENV_FILES[@]}
	do
		rm "$ENV_FILE" \
			&& SUCCESS "removed '$ENV_FILE'" \
			|| ERROR "unable to remove '$ENV_FILE'; is it protected?" \
			;
	done
	
	CHECK_ERRORS -n || FAIL 2 "some errors ocurred when cleaning up $ENV_NAME"
}
