Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix handling when search returns multiple JSON formatted results
Brad Davis committed 1 month ago
commit df7c6bdbf0e868c692ad8ce3cd9752e6b8937cea
parent 70eac91
3 files changed +32 -2
modified src/search.c
@@ -467,10 +467,23 @@ exec_search(int argc, char **argv)
	}

	flags = info_flags(opt, true);
+
	if ((opt & INFO_RAW) &&
+
		(opt & (INFO_RAW_JSON | INFO_RAW_JSON_COMPACT))) {
+
			printf("[");
+
	}
	while ((ret = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {
+
		if ((opt & INFO_RAW) &&
+
			(opt & (INFO_RAW_JSON | INFO_RAW_JSON_COMPACT)) &&
+
			(atleastone)) {
+
				printf(",");
+
		}
		print_info(NULL, pkg, opt);
		atleastone = true;
	}
+
	if ((opt & INFO_RAW) &&
+
		(opt & (INFO_RAW_JSON | INFO_RAW_JSON_COMPACT))) {
+
			printf("]\n");
+
	}

	pkg_free(pkg);
	pkgdb_it_free(it);
modified src/utils.c
@@ -390,8 +390,6 @@ print_info(struct pkgdb *db, struct pkg * const pkg, uint64_t options)
			outflags |= PKG_MANIFEST_EMIT_COMPACT;

		pkg_emit_manifest_file(pkg, stdout, outflags);
-
		if (outflags & PKG_MANIFEST_EMIT_COMPACT)
-
			printf("\n");
		return;
	}

modified tests/frontend/search.sh
@@ -4,6 +4,7 @@

tests_init \
	search \
+
	search_multiple_json_compact \
	search_options \
	search_comment_description

@@ -12,6 +13,24 @@ search_body() {
	atf_check -e inline:"No active remote repositories configured.\n" -o empty -s exit:3 pkg -C '' -R '' search -e -Q comment -S name pkg
}

+
search_multiple_json_compact_body() {
+
	atf_require python3 "Requires python3 to run this test"
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "testa" "testa" "1.0"
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "testb" "testb" "1.0"
+
	atf_check -s exit:0 pkg create -o "${TMPDIR}/repo" -M ./testa.ucl
+
	atf_check -s exit:0 pkg create -o "${TMPDIR}/repo" -M ./testb.ucl
+
	atf_check -s exit:0 -o ignore pkg repo "${TMPDIR}/repo"
+
	atf_check -s exit:0 mkdir reposconf
+
	cat << EOF > reposconf/repos.conf
+
repo: {
+
	url: file://${TMPDIR}/repo,
+
	enabled: true
+
}
+
EOF
+
	atf_check -s exit:0 -o save:out.json pkg --repo-conf-dir "${TMPDIR}/reposconf" search -R --raw-format json-compact test
+
	atf_check -s exit:0 -o ignore -e empty python3 -m json.tool out.json
+
}
+

search_options_body() {
	touch pkgA.file
	cat << EOF > pkgA.ucl