Beginning debug/cleanup
This commit is contained in:
@@ -237,11 +237,18 @@ ask_pn() {
|
|||||||
Make it descriptive and avoid spaces and special characters.
|
Make it descriptive and avoid spaces and special characters.
|
||||||
Example: ${example_pn}
|
Example: ${example_pn}
|
||||||
EOF
|
EOF
|
||||||
|
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
|
read -r -p "Enter a new or existing project name ($example_pn): " PROJECT
|
||||||
if [[ -z $PROJECT ]]; then
|
if [[ -z $PROJECT ]]; then
|
||||||
echo "Setting project name to the default: $example_pn"
|
|
||||||
PROJECT="$example_pn"
|
PROJECT="$example_pn"
|
||||||
|
else
|
||||||
|
sanitize_pn "$PROJECT" && break
|
||||||
|
err "Invalid project name: $PROJECT"
|
||||||
|
echo "Retrying ($i of $trys)"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
echo "Using project name: $PROJECT"
|
||||||
}
|
}
|
||||||
debug() { (( DEBUG )) && echo "Debug: $*"; }
|
debug() { (( DEBUG )) && echo "Debug: $*"; }
|
||||||
# Not super portable but nice to have
|
# Not super portable but nice to have
|
||||||
@@ -1479,7 +1486,7 @@ main() {
|
|||||||
# Set the automatic project directory prefix
|
# Set the automatic project directory prefix
|
||||||
PROJECT_USER="$(whoami)"
|
PROJECT_USER="$(whoami)"
|
||||||
PROJECT_PREFIX="${DATE}_${PROJECT_USER}" # reversed these so easier to sort and parse date
|
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
|
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
|
# Prompt user for the PROJECT if we still don't have one
|
||||||
if [[ ${#PROJECTS[@]} -eq 0 ]]; then # still allows for environment overrides
|
if [[ ${#PROJECTS[@]} -eq 0 ]]; then # still allows for environment overrides
|
||||||
|
ask_pn && PROJECTS+=("$PROJECT")
|
||||||
while :; do
|
while :; do
|
||||||
ask_pn || break
|
|| break
|
||||||
PROJECTS+=("$PROJECT")
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for i in "${!PROJECTS[@]}"; do
|
for i in "${!PROJECTS[@]}"; do
|
||||||
if ! san "${PROJECTS[i]}"; then
|
if ! sanitize_pn "${PROJECTS[i]}"; then
|
||||||
echo "Project name ${PROJECTS[i]} is invalid"
|
echo "Project name ${PROJECTS[i]} is invalid"
|
||||||
echo "Enter a replacement"
|
echo "Enter a replacement"
|
||||||
ask_pn
|
ask_pn
|
||||||
san "$PROJECT" || (echo "RTFM"; return 1)
|
sanitize_pn "$PROJECT" || (echo "RTFM"; return 1)
|
||||||
PROJECTS[i]="$PROJECT"
|
PROJECTS[i]="$PROJECT"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user