diff sbin/fports @ 800:1c4d729963dc

fports: Implement "fports detail -A" and "fports detail -M". Autoselect packages: use all non-auto packages and use all packages with a mapping in package-mapping.conf.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 01 Nov 2024 02:20:56 +0100
parents 96631c3886d9
children 8167b2a8b4fe
line wrap: on
line diff
--- a/sbin/fports	Thu Oct 31 14:56:18 2024 +0100
+++ b/sbin/fports	Fri Nov 01 02:20:56 2024 +0100
@@ -24,6 +24,8 @@
 USAGE: fports -h
        fports -V
        fports deptree [-l maxlevel] [-r] [-t] package...
+       fports detail -A
+       fports detail -M
        fports detail package...
 
 GLOBAL OPTIONS:
@@ -67,9 +69,11 @@
 #: Implementation of the "deptree" command.
 #:
 command_deptree() {
-    local opt opt_reversed opt_maxlevel opt_flat
+    local opt_reversed opt_maxlevel opt_flat
     # $@
 
+    local opt
+
     opt_maxlevel=0
     opt_reversed=no
     opt_flat=no
@@ -341,22 +345,61 @@
 #: Implementation of the "detail" command.
 #:
 command_detail() {
+    local opt_noauto opt_mapped
     # $@
 
     local package \
           repositories packagemapping instver instrepo \
-          repo title_printed indexfile _dummy \
+          repo title_printed indexfile _dummy opt acookie \
           pkglabel pkgdescr pkgversion mapped_package
 
+    opt_noauto=no
+    opt_mapped=no
+    while getopts "AM" opt; do
+        case "${opt}" in
+            A)
+                # shellcheck disable=SC2034     # appears unused
+                opt_noauto=yes;;
+            M)
+                # shellcheck disable=SC2034     # appears unused
+                opt_mapped=yes;;
+            \?)
+                exit 2;;
+            *)
+                fatal 2 "option handling failed";;
+        esac
+    done
+    shift $((OPTIND-1))
+    OPTIND=1
+
+    if checkyesno opt_noauto || checkyesno opt_mapped; then
+        [ $# -gt 0 ] && fatal "${EX_USAGE}" "packages are now allowed for options -A or -M"
+        if checkyesno opt_noauto && checkyesno opt_mapped; then
+            fatal "${EX_USAGE}" "cannot use -A and -M together"
+        fi
+    fi
+
     repositories=''
     get_active_repositories repositories
     packagemapping=''
     init_package_mapping packagemapping
     indexfile="$(get_local_index_file)"
 
-    for package in "$@"; do
-        _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}"
-    done
+    if checkyesno opt_noauto; then
+        for package in $(LC_ALL=C.UTF-8 "${PKG}" query -e '%a = 0' '%n'); do
+            _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}"
+        done
+    elif checkyesno opt_mapped; then
+        acookie="$(falist_cookie_first packagemapping)"
+        while falist_tryget_key_at package "${acookie}"; do
+            _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}"
+            acookie="$(falist_cookie_next "${acookie}")"
+        done
+    else
+        for package in "$@"; do
+            _package_max_detail "${package}" "${packagemapping}" "${repositories}" "${indexfile}"
+        done
+    fi
 
     falist_release "${packagemapping}"
     farray_release "${repositories}"