xbps-{bin,repo}: new -o flag for the 'show' target, to print specific objs value.
This commit is contained in:
@@ -66,7 +66,7 @@ int show_pkg_deps(const char *);
|
||||
int show_pkg_reverse_deps(const char *);
|
||||
|
||||
/* from show-info-files.c */
|
||||
int show_pkg_info_from_metadir(const char *);
|
||||
int show_pkg_info_from_metadir(const char *, const char *);
|
||||
int show_pkg_files_from_metadir(const char *);
|
||||
|
||||
/* from find-files.c */
|
||||
@@ -84,12 +84,13 @@ void transaction_cb(struct xbps_transaction_cb_data *);
|
||||
void transaction_err_cb(struct xbps_transaction_cb_data *);
|
||||
|
||||
/* From util.c */
|
||||
int show_pkg_files(prop_dictionary_t);
|
||||
void show_pkg_info(prop_dictionary_t);
|
||||
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
int list_strings_in_array(prop_object_t, void *, bool *);
|
||||
int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||
size_t find_longest_pkgver(prop_dictionary_t);
|
||||
void print_package_line(const char *, bool);
|
||||
int show_pkg_files(prop_dictionary_t);
|
||||
void show_pkg_info(prop_dictionary_t);
|
||||
void show_pkg_info_one(prop_dictionary_t, const char *);
|
||||
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
int list_strings_in_array(prop_object_t, void *, bool *);
|
||||
int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||
size_t find_longest_pkgver(prop_dictionary_t);
|
||||
void print_package_line(const char *, bool);
|
||||
|
||||
#endif /* !_XBPS_BIN_DEFS_H_ */
|
||||
|
||||
@@ -185,17 +185,17 @@ main(int argc, char **argv)
|
||||
struct xferstat xfer;
|
||||
struct list_pkgver_cb lpc;
|
||||
struct sigaction sa;
|
||||
const char *rootdir, *cachedir, *confdir;
|
||||
const char *rootdir, *cachedir, *confdir, *option;
|
||||
int i , c, flags, rv;
|
||||
bool yes, purge, debug, force_rm_with_deps, recursive_rm;
|
||||
bool install_auto, install_manual, show_download_pkglist_url;
|
||||
|
||||
rootdir = cachedir = confdir = NULL;
|
||||
rootdir = cachedir = confdir = option = NULL;
|
||||
flags = rv = 0;
|
||||
yes = purge = force_rm_with_deps = recursive_rm = debug = false;
|
||||
install_auto = install_manual = show_download_pkglist_url = false;
|
||||
|
||||
while ((c = getopt(argc, argv, "AC:c:dDFfMpRr:Vvy")) != -1) {
|
||||
while ((c = getopt(argc, argv, "AC:c:dDFfMo:pRr:Vvy")) != -1) {
|
||||
switch (c) {
|
||||
case 'A':
|
||||
install_auto = true;
|
||||
@@ -221,6 +221,9 @@ main(int argc, char **argv)
|
||||
case 'M':
|
||||
install_manual = true;
|
||||
break;
|
||||
case 'o':
|
||||
option = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
purge = true;
|
||||
break;
|
||||
@@ -375,7 +378,7 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
|
||||
rv = show_pkg_info_from_metadir(argv[1]);
|
||||
rv = show_pkg_info_from_metadir(argv[1], option);
|
||||
if (rv != 0) {
|
||||
printf("Package %s not installed.\n", argv[1]);
|
||||
goto out;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "defs.h"
|
||||
|
||||
int
|
||||
show_pkg_info_from_metadir(const char *pkgname)
|
||||
show_pkg_info_from_metadir(const char *pkgname, const char *option)
|
||||
{
|
||||
prop_dictionary_t d;
|
||||
|
||||
@@ -43,7 +43,11 @@ show_pkg_info_from_metadir(const char *pkgname)
|
||||
if (d == NULL)
|
||||
return EINVAL;
|
||||
|
||||
show_pkg_info(d);
|
||||
if (option == NULL)
|
||||
show_pkg_info(d);
|
||||
else
|
||||
show_pkg_info_one(d, option);
|
||||
|
||||
prop_object_release(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -40,13 +40,86 @@
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/defs.h"
|
||||
|
||||
static void
|
||||
print_value_obj(const char *keyname, prop_object_t obj, bool raw)
|
||||
{
|
||||
const char *value;
|
||||
size_t i;
|
||||
char size[8];
|
||||
|
||||
switch (prop_object_type(obj)) {
|
||||
case PROP_TYPE_STRING:
|
||||
if (!raw)
|
||||
printf("%s: ", keyname);
|
||||
printf("%s\n", prop_string_cstring_nocopy(obj));
|
||||
break;
|
||||
case PROP_TYPE_NUMBER:
|
||||
if (!raw)
|
||||
printf("%s: ", keyname);
|
||||
if (xbps_humanize_number(size,
|
||||
(int64_t)prop_number_unsigned_integer_value(obj)) == -1)
|
||||
printf("%ju\n",
|
||||
prop_number_unsigned_integer_value(obj));
|
||||
else
|
||||
printf("%s\n", size);
|
||||
break;
|
||||
case PROP_TYPE_BOOL:
|
||||
if (!raw)
|
||||
printf("%s: ", keyname);
|
||||
printf("%s\n", prop_bool_true(obj) ? "yes" : "no");
|
||||
break;
|
||||
case PROP_TYPE_ARRAY:
|
||||
if (!raw)
|
||||
printf("%s:\n", keyname);
|
||||
for (i = 0; i < prop_array_count(obj); i++) {
|
||||
prop_array_get_cstring_nocopy(obj, i, &value);
|
||||
printf("%s%s%s", !raw ? "\t" : "", value,
|
||||
!raw ? "\n" : " ");
|
||||
}
|
||||
if (raw)
|
||||
printf("\n");
|
||||
break;
|
||||
default:
|
||||
xbps_warn_printf("unknown obj type (key %s)\n",
|
||||
keyname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
show_pkg_info_one(prop_dictionary_t d, const char *keys)
|
||||
{
|
||||
prop_object_t obj;
|
||||
char *key, *p, *saveptr;
|
||||
|
||||
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
|
||||
assert(keys != NULL);
|
||||
|
||||
if (strchr(keys, ',') == NULL) {
|
||||
obj = prop_dictionary_get(d, keys);
|
||||
if (obj == NULL)
|
||||
return;
|
||||
print_value_obj(keys, obj, true);
|
||||
return;
|
||||
}
|
||||
key = strdup(keys);
|
||||
assert(key != NULL);
|
||||
for ((p = strtok_r(key, ",", &saveptr)); p;
|
||||
(p = strtok_r(NULL, ",", &saveptr))) {
|
||||
obj = prop_dictionary_get(d, p);
|
||||
if (obj == NULL)
|
||||
continue;
|
||||
print_value_obj(p, obj, true);
|
||||
}
|
||||
free(key);
|
||||
}
|
||||
|
||||
void
|
||||
show_pkg_info(prop_dictionary_t dict)
|
||||
{
|
||||
prop_array_t all_keys;
|
||||
prop_object_t obj, keysym;
|
||||
const char *keyname;
|
||||
char size[8];
|
||||
size_t i;
|
||||
|
||||
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
|
||||
@@ -57,38 +130,11 @@ show_pkg_info(prop_dictionary_t dict)
|
||||
keysym = prop_array_get(all_keys, i);
|
||||
keyname = prop_dictionary_keysym_cstring_nocopy(keysym);
|
||||
obj = prop_dictionary_get_keysym(dict, keysym);
|
||||
/* ignore run_depends, it's shown via 'show-deps' */
|
||||
if (strcmp(keyname, "run_depends") == 0)
|
||||
break;
|
||||
|
||||
switch (prop_object_type(obj)) {
|
||||
case PROP_TYPE_STRING:
|
||||
printf("%s: %s\n", keyname,
|
||||
prop_string_cstring_nocopy(obj));
|
||||
break;
|
||||
case PROP_TYPE_NUMBER:
|
||||
printf("%s: ", keyname);
|
||||
if (xbps_humanize_number(size,
|
||||
(int64_t)prop_number_unsigned_integer_value(obj)) == -1)
|
||||
printf("%ju\n",
|
||||
prop_number_unsigned_integer_value(obj));
|
||||
else
|
||||
printf("%s\n", size);
|
||||
break;
|
||||
case PROP_TYPE_BOOL:
|
||||
printf("%s: %s\n", keyname,
|
||||
prop_bool_true(obj) ? "yes" : "no");
|
||||
break;
|
||||
case PROP_TYPE_ARRAY:
|
||||
/* ignore run_depends, it's shown via 'show-deps' */
|
||||
if (strcmp(keyname, "run_depends") == 0)
|
||||
break;
|
||||
printf("%s:\n", keyname);
|
||||
(void)xbps_callback_array_iter_in_dict(dict, keyname,
|
||||
list_strings_sep_in_array, __UNCONST("\t"));
|
||||
break;
|
||||
default:
|
||||
xbps_warn_printf("unknown obj type (key %s)\n",
|
||||
keyname);
|
||||
break;
|
||||
}
|
||||
print_value_obj(keyname, obj, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH "XBPS\-BIN" "8" "17/10/2011" "\ \&" "\ \&"
|
||||
.TH "XBPS\-BIN" "8" "29/10/2011" "\ \&" "\ \&"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * set default formatting
|
||||
.\" -----------------------------------------------------------------
|
||||
@@ -88,6 +88,14 @@ option takes effect in the \fIautoupdate\fR, \fIinstall\fR and \fIupdate\fR targ
|
||||
and target packages and its required dependencies will be matched.
|
||||
.RE
|
||||
.PP
|
||||
\fB-o\fR \fIkey[,key2...]\fR
|
||||
.RS 4
|
||||
Used currently in the
|
||||
\fIshow\fR
|
||||
target\&. Prints the value of specified key(s) from package's properties dictionary.
|
||||
Multiple keys can be specified delimited by the comma character.
|
||||
.RE
|
||||
.PP
|
||||
\fB\-p\fR
|
||||
.RS 4
|
||||
Used currently in the
|
||||
|
||||
Reference in New Issue
Block a user