Skip to content

Commit ee2f8cf

Browse files
committed
add some parsing options when finding deps
Signed-off-by: Appu <appu@google.com>
1 parent 0e2e163 commit ee2f8cf

1 file changed

Lines changed: 48 additions & 4 deletions

File tree

knife

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,54 @@ function cmd_test () {
203203
}
204204

205205
function cmd_deb_versions () {
206-
echo "🔧 Printing .deb Versions (bookworm) from private/repos/deb/bookworm*.lock.json"
207-
echo ""
206+
local architecture=""
207+
local package=""
208+
local codename=""
209+
local opt
210+
local OPTIND=1
211+
212+
while getopts "a:p:c:" opt; do
213+
case "$opt" in
214+
a)
215+
architecture="$OPTARG"
216+
;;
217+
p)
218+
package="$OPTARG"
219+
;;
220+
c)
221+
codename="$OPTARG"
222+
;;
223+
*)
224+
echo "Usage: ./knife deb-versions [-a architecture] [-p package] [-c codename]" >&2
225+
exit 1
226+
;;
227+
esac
228+
done
229+
shift $((OPTIND - 1))
230+
231+
local files=()
232+
if [[ -n "$codename" ]]; then
233+
files=("private/repos/deb/${codename}"*.lock.json)
234+
# Check if files exist to avoid passing unexpanded glob if codename is invalid
235+
if [[ ! -e "${files[0]}" ]]; then
236+
echo "Error: No lock files found for codename '$codename'" >&2
237+
exit 1
238+
fi
239+
else
240+
files=(private/repos/deb/*.lock.json)
241+
fi
242+
243+
echo "🔧 Printing .deb Versions from private/repos/deb/*.lock.json" >&2
244+
[[ -n "$codename" ]] && echo " Filtering by codename: $codename" >&2
245+
[[ -n "$architecture" ]] && echo " Filtering by architecture: $architecture" >&2
246+
[[ -n "$package" ]] && echo " Filtering by package: $package" >&2
247+
echo "" >&2
208248

209-
jq -n '[inputs.packages[]] | group_by(.arch) | map({(.[0].arch): map({package: .name, version: .version})})' private/repos/deb/bookworm*.lock.json
249+
jq -n \
250+
--arg arch "$architecture" \
251+
--arg pkg "$package" \
252+
'[inputs.packages[] | select(($arch == "" or .arch == $arch) and ($pkg == "" or (.name | contains($pkg))))] | group_by(.arch) | map({(.[0].arch): map({package: .name, version: .version})})' \
253+
"${files[@]}"
210254
}
211255

212256
case "${1:-"~~nocmd"}" in
@@ -229,7 +273,7 @@ test)
229273
cmd_test
230274
;;
231275
deb-versions)
232-
cmd_deb_versions
276+
cmd_deb_versions "${@:2}"
233277
;;
234278
update-node-archives)
235279
cmd_update_node_archives

0 commit comments

Comments
 (0)