Skip to content
Browse files

add support for searching by group

  • Loading branch information...
1 parent 3d4bf93 commit 3664af8238d2a8bd2b0ca5e560a314faff50ae5e @falconindy committed Apr 5, 2011
Showing with 21 additions and 2 deletions.
  1. +4 −0 README.pod
  2. +17 −2 expac.c
View
4 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
View
19 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);

0 comments on commit 3664af8

Please sign in to comment.
Something went wrong with that request. Please try again.