Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
autoremove: add -qn for scritp friendly output
Baptiste Daroussin committed 18 days ago
commit 7bd8319a3552f1a606a19e22556bbf5d3f28db3e
parent 98a4420
3 files changed +28 -2
modified docs/pkg-autoremove.8
@@ -14,7 +14,7 @@
.\"
.\"     @(#)pkg.8
.\"
-
.Dd May 3, 2021
+
.Dd April 17, 2026
.Dt PKG-AUTOREMOVE 8
.Os
.Sh NAME
@@ -42,6 +42,9 @@ no changes are actually made.
If a deinstallation script exists for a given package, do not execute it.
.It Fl q , Cm --quiet
Force quiet output.
+
When combined with
+
.Fl n ,
+
prints one package name-version per line suitable for scripting.
.It Fl y , Cm --yes
Assume yes when asked for confirmation before package autoremoval.
.El
modified src/autoremove.c
@@ -136,7 +136,15 @@ exec_autoremove(int argc, char **argv)
		goto cleanup;
	}

-
	if (!quiet || dry_run) {
+
	if (quiet && dry_run) {
+
		/* Scripting-friendly: one package name-version per line */
+
		struct pkg *p = NULL, *old = NULL;
+
		void *iter = NULL;
+
		int t;
+
		while (pkg_jobs_iter(jobs, &iter, &p, &old, &t))
+
			pkg_printf("%n-%v\n", p, p);
+
		goto cleanup;
+
	} else if (!quiet || dry_run) {
		print_jobs_summary(jobs,
				"Deinstallation has been requested for the following %d packages:\n\n", nbactions);
		if (!dry_run)
modified tests/frontend/autoremove.sh
@@ -6,6 +6,7 @@ tests_init \
	autoremove \
	autoremove_quiet \
	autoremove_dryrun \
+
	autoremove_quiet_dryrun \
	autoremove_order

autoremove_prep() {
@@ -183,3 +184,17 @@ autoremove_dryrun_body() {

	test -f ${TMPDIR}/file1 -o -f ${TMPDIR}/file2 || atf_fail "Files are missing"
}
+

+
autoremove_quiet_dryrun_body() {
+
	autoremove_prep
+

+
	# -qn: scripting-friendly output, one package per line
+
	atf_check \
+
	    -o inline:"test-1\n" \
+
	    -e empty \
+
	    -s exit:0 \
+
	    pkg autoremove -qn
+

+
	# Package should still be installed
+
	atf_check -s exit:0 pkg info -e test
+
}