comparison sbin/fports @ 810:a59cc4bea000

fports: Add option "-f" to "fports detail": do not print the status with regard to repositories that do not have the package available
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 06 Nov 2024 01:17:23 +0100
parents ab21dd56f99e
children 70e08ff3db45
comparison
equal deleted inserted replaced
809:6cf3e1021862 810:a59cc4bea000
22 # shellcheck disable=SC2016 # no expansion 22 # shellcheck disable=SC2016 # no expansion
23 USAGE=' 23 USAGE='
24 USAGE: fports -h|--help 24 USAGE: fports -h|--help
25 fports -V|--version 25 fports -V|--version
26 fports deptree [-l maxlevel|--maxlevel=maxlevel] [-r|--reverse] [-t|--list|--transitive] package... 26 fports deptree [-l maxlevel|--maxlevel=maxlevel] [-r|--reverse] [-t|--list|--transitive] package...
27 fports detail [-A] [-b|--nofreebsd|--no-freebsd] [-n|--noauto|--no-auto] [-m|--mapped] [package...] 27 fports detail [-A] [-b|--nofreebsd|--no-freebsd] [-f|--filter-unused] [-n|--noauto|--no-auto] [-m|--mapped] [package...]
28 28
29 GLOBAL OPTIONS: 29 GLOBAL OPTIONS:
30 30
31 -V, --version Print the program name and version number to stdout and exit. 31 -V, --version Print the program name and version number to stdout and exit.
32 32
342 342
343 #: 343 #:
344 #: Implementation of the "detail" command. 344 #: Implementation of the "detail" command.
345 #: 345 #:
346 command_detail() { 346 command_detail() {
347 local opt_noauto opt_mapped 347 local opt_nofreebsd opt_filterunused opt_noauto opt_mapped opt_nofreebsd
348 # $@ 348 # $@
349 349
350 local package \ 350 local package \
351 packages do_sort idx prev_package \ 351 packages do_sort idx prev_package \
352 repositories packagemapping instver instrepo \ 352 repositories packagemapping instver instrepo \
353 repo title_printed indexfile _dummy opt acookie \ 353 repo title_printed indexfile _dummy opt acookie \
354 pkglabel pkgdescr pkgversion mapped_package 354 pkglabel pkgdescr pkgversion mapped_package
355 355
356 do_sort=no 356 do_sort=no
357 opt_filterunused=no
357 opt_nofreebsd=no 358 opt_nofreebsd=no
358 opt_noauto=no 359 opt_noauto=no
359 opt_mapped=no 360 opt_mapped=no
360 while getopts "Abnm-:" opt; do 361 while getopts "Abfnm-:" opt; do
361 postprocess_getopts_for_long "Abnm-:" opt "nofreebsd" "no-freebsd" "noauto" "no-auto" "mapped" "" 362 postprocess_getopts_for_long "Abfnm-:" opt "nofreebsd" "no-freebsd" "filter-unused" "noauto" "no-auto" "mapped" ""
362 case "${opt}" in 363 case "${opt}" in
363 A) 364 A)
364 opt_nofreebsd=yes 365 opt_nofreebsd=yes
365 opt_noauto=yes 366 opt_noauto=yes
366 opt_mapped=yes 367 opt_mapped=yes
368 ;; 369 ;;
369 b|nofreebsd|no-freebsd) 370 b|nofreebsd|no-freebsd)
370 # shellcheck disable=SC2034 # appears unused 371 # shellcheck disable=SC2034 # appears unused
371 opt_nofreebsd=yes 372 opt_nofreebsd=yes
372 do_sort=yes 373 do_sort=yes
374 ;;
375 f|filter-unused)
376 opt_filterunused=yes
373 ;; 377 ;;
374 n|noauto|no-auto) 378 n|noauto|no-auto)
375 # shellcheck disable=SC2034 # appears unused 379 # shellcheck disable=SC2034 # appears unused
376 opt_noauto=yes 380 opt_noauto=yes
377 do_sort=yes 381 do_sort=yes
394 farray_create packages 398 farray_create packages
395 repositories='' 399 repositories=''
396 get_active_repositories repositories 400 get_active_repositories repositories
397 packagemapping='' 401 packagemapping=''
398 init_package_mapping packagemapping 402 init_package_mapping packagemapping
403 falist_set packagemapping "uwsginl" "uwsgi"
399 indexfile="$(get_local_index_file)" 404 indexfile="$(get_local_index_file)"
400 405
401 if checkyesno opt_nofreebsd; then 406 if checkyesno opt_nofreebsd; then
402 while IFS='|' read -r package repo; do 407 while IFS='|' read -r package repo; do
403 [ "${repo}" != 'FreeBSD' ] && farray_append packages "${package}" 408 [ "${repo}" != 'FreeBSD' ] && farray_append packages "${package}"
424 429
425 idx=1 430 idx=1
426 prev_package='' # to skip duplicate packages 431 prev_package='' # to skip duplicate packages
427 while farray_tryget package packages "${idx}"; do 432 while farray_tryget package packages "${idx}"; do
428 if [ "${prev_package}" != "${package}" ]; then 433 if [ "${prev_package}" != "${package}" ]; then
429 _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}" 434 _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}" "${opt_filterunused}"
430 prev_package="${package}" 435 prev_package="${package}"
431 fi 436 fi
432 idx=$((idx + 1)) 437 idx=$((idx + 1))
433 done 438 done
434 439
446 #: Args: 451 #: Args:
447 #: $1 (str): The name of the package 452 #: $1 (str): The name of the package
448 #: $2 (alist): The 453 #: $2 (alist): The
449 #: $3 (array): The array with all the configured/active repositories 454 #: $3 (array): The array with all the configured/active repositories
450 #: $4 (str, null): The local index file if it exists 455 #: $4 (str, null): The local index file if it exists
456 #: $5 (bool): Flag whether to suppress details for repositories that do
457 #: not contain the package `$1`
451 #: 458 #:
452 _package_max_detail() { 459 _package_max_detail() {
453 local package packagemapping repositories indexfile 460 local package packagemapping repositories indexfile opt_filterunused
454 461
455 local instver instrepo repo title_printed _dummy \ 462 local instver instrepo repo title_printed _dummy \
456 pkglabel pkgdescr pkgversion mapped_package 463 pkglabel pkgdescr pkgversion mapped_package
457 464
458 package="${1}" 465 package="${1}"
459 packagemapping="${2}" 466 packagemapping="${2}"
460 repositories="${3}" 467 repositories="${3}"
461 indexfile="${4}" 468 indexfile="${4}"
469 opt_filterunused="${5}"
462 470
463 # shellcheck disable=SC2034 # appears unused 471 # shellcheck disable=SC2034 # appears unused
464 title_printed=no 472 title_printed=no
465 IFS='|' read -r instver instrepo <<EOF_e9bd7819-b4c5-4a86-b984-f5226db58cb1 473 IFS='|' read -r instver instrepo <<EOF_e9bd7819-b4c5-4a86-b984-f5226db58cb1
466 $(LC_ALL=C.UTF-8 "${PKG}" query '%v|%R' "${package}") 474 $(LC_ALL=C.UTF-8 "${PKG}" query '%v|%R' "${package}")
469 if [ -n "${indexfile}" ]; then 477 if [ -n "${indexfile}" ]; then
470 read -r _dummy pkglabel pkgdescr <<EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c 478 read -r _dummy pkglabel pkgdescr <<EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c
471 $(LC_ALL=C.UTF-8 "${PKG}" version -U -I -n "${package}" -v "${indexfile}") 479 $(LC_ALL=C.UTF-8 "${PKG}" version -U -I -n "${package}" -v "${indexfile}")
472 EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c 480 EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c
473 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${package}")" 481 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${package}")"
474 print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" "${pkgdescr}" 482 _shall_print_package_detail_item "${pkglabel}" "${opt_filterunused}" && print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" "${pkgdescr}"
475 fi 483 fi
476 farray_for_each repositories _package_repository_detail "${package}" 0 484 farray_for_each repositories _package_repository_detail "${package}" "${opt_filterunused}" 0
477 mapped_package="$(get_package_mapping "${packagemapping}" "${package}")" 485 mapped_package="$(get_package_mapping "${packagemapping}" "${package}")"
478 if [ -n "${mapped_package}" ]; then 486 if [ -n "${mapped_package}" ]; then
479 printf '%18s %s\n' "--------------->" "${mapped_package}" 487 printf '%18s %s\n' "--------------->" "${mapped_package}"
480 if [ -n "${indexfile}" ]; then 488 if [ -n "${indexfile}" ]; then
481 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${mapped_package}")" 489 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${mapped_package}")"
482 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${instver}" "${pkgversion}")" 490 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${instver}" "${pkgversion}")"
483 print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" '' 19 491 print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" '' 19
484 fi 492 fi
485 farray_for_each repositories _mapped_package_repository_detail "${mapped_package}" "{instver}" 19 493 farray_for_each repositories _mapped_package_repository_detail "${mapped_package}" "{instver}" "${opt_filterunused}" 19
486 fi 494 fi
495 }
496
497
498 #:
499 #: Args:
500 #: $1 (str): The repositorie's package label string
501 #: $2 (bool): The flag whether to filter package detail data
502 #:
503 #: Returns:
504 #: int: 0 (truthy) if the detail should be printed
505 #: 1 (falsy) if printing should be suppressed
506 #:
507 _shall_print_package_detail_item() {
508 # $1 $2
509
510 # If filtering is disabled then print
511 checkyesnovalue "$2" || return 0
512 if [ -z "$1" ] || [ "$1" = '?' ]; then
513 return 1
514 fi
515 return 0
487 } 516 }
488 517
489 518
490 #: 519 #:
491 #: Array callback to print package details with regard to a repository. 520 #: Array callback to print package details with regard to a repository.
493 #: Args: 522 #: Args:
494 #: $1 (str): The repositories array 523 #: $1 (str): The repositories array
495 #: $2 (int): The current index 524 #: $2 (int): The current index
496 #: $3: The element value (i.e. repository name) 525 #: $3: The element value (i.e. repository name)
497 #: $4 (str): The (master) package name 526 #: $4 (str): The (master) package name
498 #: $5 (int): The extra indent value to forward to called functions 527 #: $5 (flag): The global flat whether to filter repository printing
528 #: $6 (int, optional): The extra indent value to forward to called functions
499 #: 529 #:
500 _package_repository_detail() { 530 _package_repository_detail() {
501 local repositories idx reponame package extraindent 531 local repositories idx reponame package extraindent opt_filterunused
502 532
503 local _dummy \ 533 local _dummy \
504 pkglabel pkgdescr pkgversion 534 pkglabel pkgdescr pkgversion
505 535
506 repositories="${1}" 536 repositories="${1}"
507 # shellcheck disable=SC2034 # appears unused (yes, accept it) 537 # shellcheck disable=SC2034 # appears unused (yes, accept it)
508 idx="${2}" 538 idx="${2}"
509 reponame="${3}" 539 reponame="${3}"
510 package="${4}" 540 package="${4}"
511 extraindent="${5:-0}" 541 opt_filterunused="${5}"
512 542 extraindent="${6:-0}"
543
513 read -r _dummy pkglabel pkgdescr <<EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206 544 read -r _dummy pkglabel pkgdescr <<EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206
514 $(LC_ALL=C.UTF-8 "${PKG}" version -U -R -r "${reponame}" -n "${package}" -v) 545 $(LC_ALL=C.UTF-8 "${PKG}" version -U -R -r "${reponame}" -n "${package}" -v)
515 EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206 546 EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206
516 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")" 547 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")"
517 print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" "${pkgdescr}" "${extraindent}" 548 _shall_print_package_detail_item "${pkglabel}" "${opt_filterunused}" && print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" "${pkgdescr}" "${extraindent}"
518 } 549 }
519 550
520 551
521 #: 552 #:
522 #: Array callback to print package details for a mapped package with regard 553 #: Array callback to print package details for a mapped package with regard
526 #: $1 (str): The repositories array 557 #: $1 (str): The repositories array
527 #: $2 (int): The current index 558 #: $2 (int): The current index
528 #: $3: The element value (i.e. repository name) 559 #: $3: The element value (i.e. repository name)
529 #: $4 (str): The mapped package name 560 #: $4 (str): The mapped package name
530 #: $5 (str): The parent package version 561 #: $5 (str): The parent package version
531 #: $6 (int): The extra indent value to forward to called functions 562 #: $6 (flag): The global flat whether to filter repository printing
563 #: $7 (int, optional): The extra indent value to forward to called functions
532 #: 564 #:
533 _mapped_package_repository_detail() { 565 _mapped_package_repository_detail() {
534 local repositories idx reponame package parent_pkgversion extraindent 566 local repositories idx reponame package parent_pkgversion \
567 opt_filterunused extraindent
535 568
536 local _dummy \ 569 local _dummy \
537 pkglabel pkgversion 570 pkglabel pkgversion
538 571
539 repositories="${1}" 572 repositories="${1}"
540 # shellcheck disable=SC2034 # appears unused (yes, accept it) 573 # shellcheck disable=SC2034 # appears unused (yes, accept it)
541 idx="${2}" 574 idx="${2}"
542 reponame="${3}" 575 reponame="${3}"
543 package="${4}" 576 package="${4}"
544 parent_pkgversion="${5}" 577 parent_pkgversion="${5}"
545 extraindent="${6:-0}" 578 opt_filterunused="${6}"
579 extraindent="${7:-0}"
546 580
547 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")" 581 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")"
548 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${parent_pkgversion}" "${pkgversion}")" 582 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${parent_pkgversion}" "${pkgversion}")"
549 print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" '' "${extraindent}" 583 _shall_print_package_detail_item "${pkglabel}" "${opt_filterunused}" && print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" '' "${extraindent}"
550 } 584 }
551 585
552 586
553 #: 587 #:
554 #: Print the output title line for a package. 588 #: Print the output title line for a package.