Allow project add in header
This commit is contained in:
@@ -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
|
||||||
echo "Available Projects:"
|
|
||||||
projects=("${projects[@]%/}") # strip comma first!
|
if [[ ${#projects[@]} -eq 0 ]]; then
|
||||||
projects=("${projects[@]##*/}")
|
echo "No projects found in $SCANS_DIR"
|
||||||
for i in "${!projects[@]}"; do
|
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
|
||||||
printf "%d. %s\n" "$((i+1))" "${projects[i]}"
|
else
|
||||||
done
|
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 ""
|
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[@]}))
|
||||||
echo "Enter a comma-separated list of project numbers to analyze"
|
if [[ $num -eq 0 ]]; then
|
||||||
read -r -p "Or hit Enter to add a new project" response
|
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
|
||||||
[[ -z $response ]] && ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
|
else
|
||||||
((YES)) || read -r -p "Hit enter for default ($num): " response
|
echo "Enter a comma-separated list of project numbers to analyze"
|
||||||
[[ -z $response ]] && response=$num
|
((YES)) || read -r -p "Enter \"new\" to add a new project or hit Enter for default ($num): " response
|
||||||
IFS=',' read -ra arr <<< "$response"
|
if [[ $response == "new" ]]; then
|
||||||
for i in "${arr[@]}"; do
|
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
|
||||||
PROJECTS+=("${projects[$((i-1))]}")
|
else
|
||||||
done
|
[[ -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
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user