Allow project add in header

This commit is contained in:
2024-08-02 21:54:00 -04:00
parent cff0b431f1
commit a24df512d5

View File

@@ -222,11 +222,10 @@ ask_pn() {
If entering a new project, use the suggested prefix: ${PROJECT_PREFIX}_ If entering a new project, use the suggested prefix: ${PROJECT_PREFIX}_
You may choose any combination of words/characters following the prefix, but be sensible. You may choose any combination of words/characters following the prefix, but be sensible.
Make it descriptive and avoid spaces and special characters. Make it descriptive and avoid spaces and special characters.
Example: ${example_pn}
EOF EOF
trys=3 # give the user up to 3 tries to enter a valid project name trys=3 # give the user up to 3 tries to enter a valid project name
for ((i=1; i<=trys; i++)); do for ((i=1; i<=trys; i++)); do
read -r -p "Enter a new or existing project name or enter for default ($example_pn): " response read -r -p "Enter a new or existing project name or hit Enter for default ($example_pn): " response
if [[ -z $response ]]; then if [[ -z $response ]]; then
ADD_PROJECTS+=("$example_pn") ADD_PROJECTS+=("$example_pn")
break break
@@ -374,29 +373,42 @@ interactive_header() {
shopt -s nullglob shopt -s nullglob
projects=("$SCANS_DIR"/*/) projects=("$SCANS_DIR"/*/)
shopt -u nullglob shopt -u nullglob
if [[ ${#projects[@]} -eq 0 ]]; then
echo "No projects found in $SCANS_DIR"
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
else
echo "Available Projects:" echo "Available Projects:"
projects=("${projects[@]%/}") # strip comma first! projects=("${projects[@]%/}") # strip comma first!
projects=("${projects[@]##*/}") projects=("${projects[@]##*/}")
for i in "${!projects[@]}"; do for i in "${!projects[@]}"; do
printf "%d. %s\n" "$((i+1))" "${projects[i]}" printf "%d. %s\n" "$((i+1))" "${projects[i]}"
done done
fi
echo "" echo ""
# Let user choose project(s) # Let user choose or add project(s)
if [[ -z ${PROJECTS[*]} ]]; then if [[ -z ${PROJECTS[*]} ]]; then
num=$((${#projects[@]})) num=$((${#projects[@]}))
if [[ $num -eq 0 ]]; then
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
else
echo "Enter a comma-separated list of project numbers to analyze" echo "Enter a comma-separated list of project numbers to analyze"
read -r -p "Or hit Enter to add a new project" response ((YES)) || read -r -p "Enter \"new\" to add a new project or hit Enter for default ($num): " response
[[ -z $response ]] && ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") if [[ $response == "new" ]]; then
((YES)) || read -r -p "Hit enter for default ($num): " response ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
else
[[ -z $response ]] && response=$num [[ -z $response ]] && response=$num
IFS=',' read -ra arr <<< "$response" IFS=',' read -ra arr <<< "$response"
for i in "${arr[@]}"; do for i in "${arr[@]}"; do
PROJECTS+=("${projects[$((i-1))]}") PROJECTS+=("${projects[$((i-1))]}")
done done
fi
fi
unset response arr i unset response arr i
fi fi
# Sanitize project names
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"
@@ -1850,7 +1862,6 @@ main() {
continue 2 # skip the command string continue 2 # skip the command string
done done
done done
} }