Beginning debug/cleanup

This commit is contained in:
2024-07-29 11:37:51 -04:00
parent 1e92e97110
commit 40a4e7d486

View File

@@ -237,11 +237,18 @@ ask_pn() {
Make it descriptive and avoid spaces and special characters.
Example: ${example_pn}
EOF
read -r -p "Enter a new or existing project name ($example_pn): " PROJECT
if [[ -z $PROJECT ]]; then
echo "Setting project name to the default: $example_pn"
PROJECT="$example_pn"
fi
trys=3
for ((i=1; i<=$trys; i++)); do # give the user up to 3 tries
read -r -p "Enter a new or existing project name ($example_pn): " PROJECT
if [[ -z $PROJECT ]]; then
PROJECT="$example_pn"
else
sanitize_pn "$PROJECT" && break
err "Invalid project name: $PROJECT"
echo "Retrying ($i of $trys)"
fi
done
echo "Using project name: $PROJECT"
}
debug() { (( DEBUG )) && echo "Debug: $*"; }
# Not super portable but nice to have
@@ -1479,7 +1486,7 @@ main() {
# Set the automatic project directory prefix
PROJECT_USER="$(whoami)"
PROJECT_PREFIX="${DATE}_${PROJECT_USER}" # reversed these so easier to sort and parse date
san() { [[ $1 =~ [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_.+_.+ ]]; } # sanitizer regex for prefix
sanitize_pn() { [[ $1 =~ [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_.+_.+ ]]; } # sanitizer regex for prefix
declare -ag PROJECTS=() # this array will hold all of the projects for this run
@@ -1487,18 +1494,21 @@ main() {
# Prompt user for the PROJECT if we still don't have one
if [[ ${#PROJECTS[@]} -eq 0 ]]; then # still allows for environment overrides
ask_pn && PROJECTS+=("$PROJECT")
while :; do
ask_pn || break
PROJECTS+=("$PROJECT")
|| break
done
fi
for i in "${!PROJECTS[@]}"; do
if ! san "${PROJECTS[i]}"; then
if ! sanitize_pn "${PROJECTS[i]}"; then
echo "Project name ${PROJECTS[i]} is invalid"
echo "Enter a replacement"
ask_pn
san "$PROJECT" || (echo "RTFM"; return 1)
sanitize_pn "$PROJECT" || (echo "RTFM"; return 1)
PROJECTS[i]="$PROJECT"
fi
done