summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-04-05 09:49:57 -0400
committerDave Reisner <d@falconindy.com>2011-04-05 09:49:57 -0400
commit3664af8238d2a8bd2b0ca5e560a314faff50ae5e (patch)
treee84915a7a8f291bdf2f0478491ba1824502ccb61
parent3d4bf93a8ce123dd603163893aac0c3e5371c7c0 (diff)
downloadexpac-3664af8238d2a8bd2b0ca5e560a314faff50ae5e.tar.xz
add support for searching by group
-rw-r--r--README.pod4
-rw-r--r--expac.c19
2 files changed, 21 insertions, 2 deletions
diff --git a/README.pod b/README.pod
index 8c5ea3c..a420c9d 100644
--- a/README.pod
+++ b/README.pod
@@ -33,6 +33,10 @@ Search the local database for provided targets. This is the default behavior.
Search for packages matching the strings specified by targets. This is a
boolean AND query and regex is allowed.
+=item B<-g, --group>
+
+Return packages matching the specified targets as package groups.
+
=item B<-d, --delim> <string>
Separate each package with the specified I<string>. The default value is a
diff --git a/expac.c b/expac.c
index df1da11..00b9213 100644
--- a/expac.c
+++ b/expac.c
@@ -51,6 +51,7 @@ alpm_list_t *targets = NULL;
bool verbose = false;
bool search = false;
bool local = false;
+bool groups = false;
const char *format = NULL;
const char *timefmt = NULL;
const char *listdelim = NULL;
@@ -167,7 +168,8 @@ static void usage(void) {
" Options:\n"
" -Q, --local search local DB (default)\n"
" -S, --sync search sync DBs\n"
- " -s, --search search for matching strings\n\n"
+ " -s, --search search for matching regex\n\n"
+ " -g, --group return packages matching targets as groups\n"
" -d, --delim <string> separator used between packages (default: \"\\n\")\n"
" -l, --listdelim <string> separator used between list elements (default: \" \")\n"
" -t, --timefmt <fmt> date format passed to strftime (default: \"%%c\")\n\n"
@@ -181,6 +183,7 @@ static int parse_options(int argc, char *argv[]) {
static struct option opts[] = {
{"delim", required_argument, 0, 'd'},
{"listdelim", required_argument, 0, 'l'},
+ {"group", required_argument, 0, 'g'},
{"help", no_argument, 0, 'h'},
{"local", no_argument, 0, 'Q'},
{"sync", no_argument, 0, 'S'},
@@ -190,7 +193,7 @@ static int parse_options(int argc, char *argv[]) {
{0, 0, 0, 0}
};
- while (-1 != (opt = getopt_long(argc, argv, "l:d:hf:QSst:v", opts, &option_index))) {
+ while (-1 != (opt = getopt_long(argc, argv, "l:d:ghf:QSst:v", opts, &option_index))) {
switch (opt) {
case 'S':
if (dblist) {
@@ -210,6 +213,9 @@ static int parse_options(int argc, char *argv[]) {
case 'd':
delim = optarg;
break;
+ case 'g':
+ groups = true;
+ break;
case 'l':
listdelim = optarg;
break;
@@ -489,6 +495,15 @@ static alpm_list_t *resolve_pkg(alpm_list_t *targets) {
for (r = dblist; r; r = alpm_list_next(r)) {
ret = alpm_list_join(ret, alpm_db_search(alpm_list_getdata(r), targets));
}
+ } else if (groups) {
+ for (t = targets; t; t = alpm_list_next(t)) {
+ for (r = dblist; r; r = alpm_list_next(r)) {
+ pmgrp_t *grp = alpm_db_readgrp(alpm_list_getdata(r), alpm_list_getdata(t));
+ if (grp) {
+ ret = alpm_list_join(ret, alpm_list_copy(alpm_grp_get_pkgs(grp)));
+ }
+ }
+ }
} else {
for (t = targets; t; t = alpm_list_next(t)) {
pkgname = reponame = alpm_list_getdata(t);