changeset 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
files docs/man/man8/fports.rst sbin/fports
diffstat 2 files changed, 69 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/docs/man/man8/fports.rst	Thu Oct 31 14:56:18 2024 +0100
+++ b/docs/man/man8/fports.rst	Fri Nov 01 02:20:56 2024 +0100
@@ -15,6 +15,10 @@
 
 **fports deptree** [**-l** `maxlevel`] [**-r**] [**t**] `package` ...
 
+**fports detail -A**
+
+**fports detail -M**
+
 **fports detail** `package` ...
 
 
@@ -71,9 +75,14 @@
      that depend on a given `package`.
 
 
+**fports detail -A**
+
+**fports detail -M**
+
 **fports detail** `package` ...
 
-  Print the status of all given packages in the most detail possible.
+  Print the status of all given or selected packages in the most
+  detail possible.
 
   The status of the package is printed with regard to its installation status,
   local index (if it exists) and all configured and active repositories.
@@ -81,6 +90,17 @@
   A package mapping is considered also if applicable.
   See :manpage:`package-mapping.conf(5)`.
 
+  .. program:: fports deptree
+
+  .. option:: -A
+
+     Automatically select all packages that are *not* installed automatically.
+
+  .. option:: -M
+
+     Automatically select all packages that have a package mapping entry
+     in :file:`package-mapping.conf`. See :manpage:`package-mapping.conf(5)`.
+
 
 Environment
 -----------
--- 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}"