Beginning debug/cleanup

This commit is contained in:
2024-07-29 11:42:31 -04:00
parent 40a4e7d486
commit c195d45f3a

View File

@@ -237,8 +237,8 @@ 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 trys=3 # give the user up to 3 tries to enter a valid project name
for ((i=1; i<=$trys; i++)); do # give the user up to 3 tries for ((i=1; i<=trys; i++)); do
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
PROJECT="$example_pn" PROJECT="$example_pn"
@@ -248,6 +248,7 @@ ask_pn() {
echo "Retrying ($i of $trys)" echo "Retrying ($i of $trys)"
fi fi
done done
[[ -z $PROJECT ]] && exit 1 # TODO eventually switch to return, but treat as fatal for now
echo "Using project name: $PROJECT" echo "Using project name: $PROJECT"
} }
debug() { (( DEBUG )) && echo "Debug: $*"; } debug() { (( DEBUG )) && echo "Debug: $*"; }
@@ -1493,23 +1494,15 @@ main() {
parse_input "$@" # parse arguments with getopt parse_input "$@" # parse arguments with getopt
# 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
ask_pn && PROJECTS+=("$PROJECT") ask_pn && PROJECTS+=("$PROJECT")
while :; do
|| break
done
fi fi
for i in "${!PROJECTS[@]}"; do for i in "${!PROJECTS[@]}"; do
if ! sanitize_pn "${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 && PROJECTS[i]="$PROJECT"
sanitize_pn "$PROJECT" || (echo "RTFM"; return 1)
PROJECTS[i]="$PROJECT"
fi fi
done done