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