diff options
author | Dave Reisner <d@falconindy.com> | 2011-05-29 11:10:12 -0400 |
---|---|---|
committer | Dave Reisner <d@falconindy.com> | 2011-05-29 11:10:12 -0400 |
commit | ccd22f9607f3b719d1c890e14faf778f900014a5 (patch) | |
tree | 1a13b7548c4c22bdc31fb1459027c0852da0ef8a | |
parent | bad9776095209b2174b82cad9045f7d4a7a785fc (diff) | |
download | expac-ccd22f9607f3b719d1c890e14faf778f900014a5.tar.xz |
add -1 option for limited -S operations
-rw-r--r-- | README.pod | 5 | ||||
-rw-r--r-- | expac.c | 13 |
2 files changed, 16 insertions, 2 deletions
@@ -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> <string> Separate each package with the specified I<string>. The default value is a @@ -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 <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[]) { 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; + } } } } |