Skip to content

Commit

Permalink
info: if multiple items are given, output an array
Browse files Browse the repository at this point in the history
  • Loading branch information
dch committed Jan 22, 2025
1 parent c06f094 commit 9b1bd0d
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ exec_info(int argc, char **argv)
if (opt & INFO_RAW) {
if ((opt & (INFO_RAW_JSON|INFO_RAW_JSON_COMPACT|INFO_RAW_UCL)) == 0)
opt |= INFO_RAW_YAML;

/* Output array start for multiple items */
if (argc > 1 || match == MATCH_ALL) {
if (opt & (INFO_RAW_JSON|INFO_RAW_JSON_COMPACT|INFO_RAW_UCL))
printf("[\n");
else if (opt & INFO_RAW_YAML)
printf("---\n");
}
}

if (file != NULL) {
Expand Down Expand Up @@ -497,10 +505,26 @@ exec_info(int argc, char **argv)
break;
}
}
if (pkg_exists)
if (pkg_exists) {
retcode = EXIT_SUCCESS;
else
} else {
print_info(pkg, opt);
/* Add separator after item (except for last) */
if (opt & INFO_RAW && (argc > 1 || match == MATCH_ALL)) {
struct pkg *next = NULL;
int peek = pkgdb_it_next(it, &next, query_flags);
if (peek == EPKG_OK || i < argc -1) {
if (opt & (INFO_RAW_JSON|INFO_RAW_JSON_COMPACT|INFO_RAW_UCL))
printf(",\n");
else if (opt & INFO_RAW_YAML)
printf("\n---\n");
}
if (next != NULL)
pkg_free(next);
if (peek == EPKG_OK)
pkgdb_it_reset(it);
}
}
}
if (ret != EPKG_END) {
retcode = EXIT_FAILURE;
Expand All @@ -520,6 +544,12 @@ exec_info(int argc, char **argv)
cleanup:
pkg_free(pkg);

/* Output array end */
if (opt & INFO_RAW && (argc > 1 || match == MATCH_ALL)) {
if (opt & (INFO_RAW_JSON|INFO_RAW_JSON_COMPACT|INFO_RAW_UCL))
printf("]\n");
}

pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
pkgdb_close(db);

Expand Down

0 comments on commit 9b1bd0d

Please sign in to comment.