-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-pages-by-feature-name.sh
45 lines (41 loc) · 1.13 KB
/
find-pages-by-feature-name.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Get the options
Name=""
Csv=False
while getopts ":hn:c" option; do
case $option in
n) # Enter a name
Name=$OPTARG;;
c) # CSV output
Csv=True;;
h) # Help message
echo "Usage: $0 -n name [-c]"
echo " -c for CSV output you can pipe to a file"
exit 0;;
\?) # Invalid option
echo "Error: Invalid option"
exit 1;;
esac
done
# Check if the name is at least 2 characters long
if [[ -z "$Name" || ${#Name} -lt 2 ]]; then
echo "Error: A feature name with at least 2 characters is required."
exit 1
fi
QUERY="SELECT * FROM view_page_and_template
WHERE pageOrTemplateId IN (
SELECT DISTINCT pageOrTemplateId
FROM view_rendering
LEFT JOIN view_page_and_template ON view_page_and_template.published = view_rendering.renderingVersionId
WHERE pageOrTemplateId IS NOT NULL
AND featureName = '${Name}'
)"
if [[ $Csv == "True" ]]; then
QUERY="COPY ($QUERY) TO STDOUT WITH (FORMAT CSV, HEADER);"
else
# Print the header
YELLOW='\033[0;33m'
RESET='\033[0m'
echo "${YELLOW}\n--- All published pages using feature: ${Name} ---\n${RESET}"
fi
duckdb _tmpview.db "$QUERY"