From 3664af8238d2a8bd2b0ca5e560a314faff50ae5e Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 5 Apr 2011 09:49:57 -0400 Subject: add support for searching by group --- README.pod | 4 ++++ expac.c | 19 +++++++++++++++++-- 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> Separate each package with the specified I. 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 separator used between packages (default: \"\\n\")\n" " -l, --listdelim separator used between list elements (default: \" \")\n" " -t, --timefmt 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); -- cgit v1.2.3-54-g00ecf