From ccd22f9607f3b719d1c890e14faf778f900014a5 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 29 May 2011 11:10:12 -0400 Subject: add -1 option for limited -S operations --- README.pod | 5 +++++ expac.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.pod b/README.pod index a420c9d..62a79d9 100644 --- a/README.pod +++ b/README.pod @@ -37,6 +37,11 @@ boolean AND query and regex is allowed. Return packages matching the specified targets as package groups. +=item B<-1, --readone> + +Stop searching after the first result. This only has an effect on -S operations +without -s. + =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 fbed45d..4f075e8 100644 --- a/expac.c +++ b/expac.c @@ -48,6 +48,7 @@ static char const printf_flags[] = "'-+ #0I"; pmdb_t *db_local = NULL; alpm_list_t *dblist = NULL; alpm_list_t *targets = NULL; +bool readone = false; bool verbose = false; bool search = false; bool local = false; @@ -169,7 +170,8 @@ static void usage(void) { " -Q, --local search local DB (default)\n" " -S, --sync search sync DBs\n" " -s, --search search for matching regex\n" - " -g, --group return packages matching targets as groups\n\n" + " -g, --group return packages matching targets as groups\n" + " -1, --readone return only the first result of a sync search\n\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[]) { int opt, option_index = 0; static struct option opts[] = { + {"readone", no_argument, 0, '1'}, {"delim", required_argument, 0, 'd'}, {"listdelim", required_argument, 0, 'l'}, {"group", required_argument, 0, 'g'}, @@ -193,7 +196,7 @@ static int parse_options(int argc, char *argv[]) { {0, 0, 0, 0} }; - while (-1 != (opt = getopt_long(argc, argv, "l:d:ghf:QSst:v", opts, &option_index))) { + while (-1 != (opt = getopt_long(argc, argv, "1l: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[]) { dblist = alpm_list_add(dblist, db_local); local = true; break; + case '1': + readone = true; + break; case 'd': delim = optarg; break; @@ -536,6 +542,9 @@ static alpm_list_t *resolve_pkg(alpm_list_t *targets) { } ret = alpm_list_add(ret, pkg); + if (readone) { + return ret; + } } } } -- cgit v1.2.3-70-g09d2