bin/xbps-uhelper: allow multiple arguments for many actions

This commit is contained in:
classabbyamp 2023-02-09 05:21:54 -05:00 committed by Duncan Overbruck
parent 06fbbba2e5
commit 83e66e215a

View File

@ -49,17 +49,17 @@ usage(void)
" real-version, arch, getsystemdir\n" " real-version, arch, getsystemdir\n"
"\n" "\n"
" Action arguments:\n" " Action arguments:\n"
" binpkgarch\t<binpkg>\n" " binpkgarch\t<binpkg> ...\n"
" binpkgver\t<binpkg>\n" " binpkgver\t<binpkg> ...\n"
" cmpver\t\t<instver> <reqver>\n" " cmpver\t\t<instver> <reqver>\n"
" getpkgdepname\t<string>\n" " getpkgdepname\t<string> ...\n"
" getpkgdepversion\t<string>\n" " getpkgdepversion\t<string> ...\n"
" getpkgname\t\t<string>\n" " getpkgname\t\t<string> ...\n"
" getpkgrevision\t<string>\n" " getpkgrevision\t<string> ...\n"
" getpkgversion\t<string>\n" " getpkgversion\t<string> ...\n"
" pkgmatch\t\t<pkg-version> <pkg-pattern>\n" " pkgmatch\t\t<pkg-version> <pkg-pattern>\n"
" version\t\t<pkgname>\n" " version\t\t<pkgname> ...\n"
" real-version\t<pkgname>\n" " real-version\t<pkgname> ...\n"
"\n" "\n"
" Options shared by all actions:\n" " Options shared by all actions:\n"
" -C\t\tPath to xbps.conf file.\n" " -C\t\tPath to xbps.conf file.\n"
@ -103,7 +103,7 @@ main(int argc, char **argv)
struct xferstat xfer; struct xferstat xfer;
const char *version, *rootdir = NULL, *confdir = NULL; const char *version, *rootdir = NULL, *confdir = NULL;
char pkgname[XBPS_NAME_SIZE], *filename; char pkgname[XBPS_NAME_SIZE], *filename;
int flags = 0, c, rv = 0; int flags = 0, c, rv = 0, i = 0;
const struct option longopts[] = { const struct option longopts[] = {
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -160,102 +160,133 @@ main(int argc, char **argv)
} }
if (strcmp(argv[0], "version") == 0) { if (strcmp(argv[0], "version") == 0) {
/* Prints version of an installed package */ /* Prints version of installed packages */
if (argc != 2) if (argc < 2)
usage(); usage();
if ((((dict = xbps_pkgdb_get_pkg(&xh, argv[1])) == NULL)) && for (i = 1; i < argc; i++) {
(((dict = xbps_pkgdb_get_virtualpkg(&xh, argv[1])) == NULL))) if ((((dict = xbps_pkgdb_get_pkg(&xh, argv[i])) == NULL)) &&
exit(EXIT_FAILURE); (((dict = xbps_pkgdb_get_virtualpkg(&xh, argv[i])) == NULL))) {
xbps_error_printf("Could not find package '%s'\n", argv[i]);
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version); rv = 1;
printf("%s\n", xbps_pkg_version(version)); } else {
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version);
printf("%s\n", xbps_pkg_version(version));
}
}
} else if (strcmp(argv[0], "real-version") == 0) { } else if (strcmp(argv[0], "real-version") == 0) {
/* Prints version of an installed real package, not virtual */ /* Prints version of installed real packages, not virtual */
if (argc != 2) if (argc < 2)
usage(); usage();
if ((dict = xbps_pkgdb_get_pkg(&xh, argv[1])) == NULL) for (i = 1; i < argc; i++) {
exit(EXIT_FAILURE); if ((dict = xbps_pkgdb_get_pkg(&xh, argv[i])) == NULL) {
xbps_error_printf("Could not find package '%s'\n", argv[i]);
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version); rv = 1;
printf("%s\n", xbps_pkg_version(version)); } else {
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version);
printf("%s\n", xbps_pkg_version(version));
}
}
} else if (strcmp(argv[0], "getpkgversion") == 0) { } else if (strcmp(argv[0], "getpkgversion") == 0) {
/* Returns the version of a pkg string */ /* Returns the version of pkg strings */
if (argc != 2) if (argc < 2)
usage(); usage();
version = xbps_pkg_version(argv[1]); for (i = 1; i < argc; i++) {
if (version == NULL) { version = xbps_pkg_version(argv[i]);
fprintf(stderr, if (version == NULL) {
"Invalid string, expected <string>-<version>_<revision>\n"); xbps_error_printf(
exit(EXIT_FAILURE); "Invalid string '%s', expected <string>-<version>_<revision>\n", argv[i]);
rv = 1;
} else {
printf("%s\n", version);
}
} }
printf("%s\n", version);
} else if (strcmp(argv[0], "getpkgname") == 0) { } else if (strcmp(argv[0], "getpkgname") == 0) {
/* Returns the name of a pkg string */ /* Returns the name of pkg strings */
if (argc != 2) if (argc < 2)
usage(); usage();
if (!xbps_pkg_name(pkgname, sizeof(pkgname), argv[1])) { for (i = 1; i < argc; i++) {
fprintf(stderr, if (!xbps_pkg_name(pkgname, sizeof(pkgname), argv[i])) {
"Invalid string, expected <string>-<version>_<revision>\n"); xbps_error_printf(
exit(EXIT_FAILURE); "Invalid string '%s', expected <string>-<version>_<revision>\n", argv[i]);
rv = 1;
} else {
printf("%s\n", pkgname);
}
} }
printf("%s\n", pkgname);
} else if (strcmp(argv[0], "getpkgrevision") == 0) { } else if (strcmp(argv[0], "getpkgrevision") == 0) {
/* Returns the revision of a pkg string */ /* Returns the revision of pkg strings */
if (argc != 2) if (argc < 2)
usage(); usage();
version = xbps_pkg_revision(argv[1]); for (i = 1; i < argc; i++) {
if (version == NULL) version = xbps_pkg_revision(argv[1]);
exit(EXIT_SUCCESS); if (version == NULL) {
rv = 1;
printf("%s\n", version); } else {
printf("%s\n", version);
}
}
} else if (strcmp(argv[0], "getpkgdepname") == 0) { } else if (strcmp(argv[0], "getpkgdepname") == 0) {
/* Returns the pkgname of a dependency */ /* Returns the pkgname of dependencies */
if (argc != 2) if (argc < 2)
usage(); usage();
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[1])) for (i = 1; i < argc; i++) {
exit(EXIT_FAILURE); if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[i])) {
xbps_error_printf("Invalid string '%s', expected <string><comparator><version>\n", argv[i]);
printf("%s\n", pkgname); rv = 1;
} else {
printf("%s\n", pkgname);
}
}
} else if (strcmp(argv[0], "getpkgdepversion") == 0) { } else if (strcmp(argv[0], "getpkgdepversion") == 0) {
/* returns the version of a package pattern dependency */ /* returns the version of package pattern dependencies */
if (argc != 2) if (argc < 2)
usage(); usage();
version = xbps_pkgpattern_version(argv[1]); for (i = 1; i < argc; i++) {
if (version == NULL) version = xbps_pkgpattern_version(argv[i]);
exit(EXIT_FAILURE); if (version == NULL) {
xbps_error_printf("Invalid string '%s', expected <string><comparator><version>\n", argv[i]);
printf("%s\n", version); rv = 1;
} else {
printf("%s\n", version);
}
}
} else if (strcmp(argv[0], "binpkgver") == 0) { } else if (strcmp(argv[0], "binpkgver") == 0) {
/* Returns the pkgver of a binpkg string */ /* Returns the pkgver of binpkg strings */
if (argc != 2) if (argc < 2)
usage(); usage();
version = xbps_binpkg_pkgver(argv[1]); for (i = 1; i < argc; i++) {
if (version == NULL) { version = xbps_binpkg_pkgver(argv[i]);
fprintf(stderr, if (version == NULL) {
"Invalid string, expected <pkgname>-<version>_<revision>.<arch>.xbps\n"); xbps_error_printf(
exit(EXIT_FAILURE); "Invalid string '%s', expected <pkgname>-<version>_<revision>.<arch>.xbps\n", argv[i]);
rv = 1;
} else {
printf("%s\n", version);
}
} }
printf("%s\n", version);
} else if (strcmp(argv[0], "binpkgarch") == 0) { } else if (strcmp(argv[0], "binpkgarch") == 0) {
/* Returns the arch of a binpkg string */ /* Returns the arch of binpkg strings */
if (argc != 2) if (argc < 2)
usage(); usage();
version = xbps_binpkg_arch(argv[1]); for (i = 1; i < argc; i++) {
if (version == NULL) { version = xbps_binpkg_arch(argv[i]);
fprintf(stderr, if (version == NULL) {
"Invalid string, expected <pkgname>-<version>_<revision>.<arch>.xbps\n"); xbps_error_printf(
exit(EXIT_FAILURE); "Invalid string '%s', expected <pkgname>-<version>_<revision>.<arch>.xbps\n", argv[i]);
rv = 1;
} else {
printf("%s\n", version);
}
} }
printf("%s\n", version);
} else if (strcmp(argv[0], "pkgmatch") == 0) { } else if (strcmp(argv[0], "pkgmatch") == 0) {
/* Matches a pkg with a pattern */ /* Matches a pkg with a pattern */
if (argc != 3) if (argc != 3)
@ -291,7 +322,7 @@ main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(); usage();
for (int i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (!xbps_file_sha256(sha256, sizeof sha256, argv[i])) { if (!xbps_file_sha256(sha256, sizeof sha256, argv[i])) {
fprintf(stderr, fprintf(stderr,
"E: couldn't get hash for %s (%s)\n", "E: couldn't get hash for %s (%s)\n",
@ -305,7 +336,7 @@ main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(); usage();
for (int i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
filename = fname(argv[i]); filename = fname(argv[i]);
rv = xbps_fetch_file_dest(&xh, argv[i], filename, "v"); rv = xbps_fetch_file_dest(&xh, argv[i], filename, "v");