File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,10 +203,54 @@ function cmd_test () {
203203}
204204
205205function 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
212256case " ${1:- " ~~nocmd" } " in
@@ -229,7 +273,7 @@ test)
229273 cmd_test
230274 ;;
231275deb-versions)
232- cmd_deb_versions
276+ cmd_deb_versions " ${ @: 2} "
233277 ;;
234278update-node-archives)
235279 cmd_update_node_archives
You can’t perform that action at this time.
0 commit comments