Add -q/--quiet option for controlling output.

Currently this only affects -Ss, -Sl, and -Q to output less information (only
package names).

In the future, we can reuse this flag for other things as well.

[Aaron: rewritten as a front-end flag]
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
[Dan: squashed commits together]
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Artyom 2007-11-07 01:05:33 -06:00 committed by Dan McGee
parent c36b0f32c6
commit 1e9a1a0292
4 changed files with 47 additions and 19 deletions

View file

@ -26,6 +26,7 @@
typedef struct __config_t { typedef struct __config_t {
char *configfile; char *configfile;
unsigned short op; unsigned short op;
unsigned short quiet;
unsigned short verbose; unsigned short verbose;
unsigned short version; unsigned short version;
unsigned short help; unsigned short help;

View file

@ -112,6 +112,7 @@ static void usage(int op, const char * const myname)
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n")); printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
printf(_(" -t, --orphans list all packages not required by any package\n")); printf(_(" -t, --orphans list all packages not required by any package\n"));
printf(_(" -u, --upgrades list all packages that can be upgraded\n")); printf(_(" -u, --upgrades list all packages that can be upgraded\n"));
printf(_(" -q --quiet show less information for query and search\n"));
} else if(op == PM_OP_SYNC) { } else if(op == PM_OP_SYNC) {
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt); printf("%s:\n", str_opt);
@ -131,6 +132,7 @@ static void usage(int op, const char * const myname)
printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n")); printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
printf(_(" --ignoregroup <grp>\n" printf(_(" --ignoregroup <grp>\n"
" ignore a group upgrade (can be used more than once)\n")); " ignore a group upgrade (can be used more than once)\n"));
printf(_(" -q --quiet show less information for query and search\n"));
} }
printf(_(" --config <path> set an alternate configuration file\n")); printf(_(" --config <path> set an alternate configuration file\n"));
printf(_(" --logfile <path> set an alternate log file\n")); printf(_(" --logfile <path> set an alternate log file\n"));
@ -286,6 +288,7 @@ static int parseargs(int argc, char *argv[])
{"owns", no_argument, 0, 'o'}, {"owns", no_argument, 0, 'o'},
{"file", no_argument, 0, 'p'}, {"file", no_argument, 0, 'p'},
{"print-uris", no_argument, 0, 'p'}, {"print-uris", no_argument, 0, 'p'},
{"quiet", no_argument, 0, 'q'},
{"root", required_argument, 0, 'r'}, {"root", required_argument, 0, 'r'},
{"recursive", no_argument, 0, 's'}, {"recursive", no_argument, 0, 's'},
{"search", no_argument, 0, 's'}, {"search", no_argument, 0, 's'},
@ -308,7 +311,7 @@ static int parseargs(int argc, char *argv[])
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygzq", opts, &option_index))) {
alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */ alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */
if(opt < 0) { if(opt < 0) {
@ -448,6 +451,9 @@ static int parseargs(int argc, char *argv[])
config->flags |= PM_TRANS_FLAG_NOCONFLICTS; config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break; break;
case 'y': (config->op_s_sync)++; break; case 'y': (config->op_s_sync)++; break;
case 'q':
config->quiet = 1;
break;
case '?': return(1); case '?': return(1);
default: return(1); default: return(1);
} }

View file

@ -146,7 +146,11 @@ static int query_search(alpm_list_t *targets)
alpm_list_t *grp; alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(i); pmpkg_t *pkg = alpm_list_getdata(i);
if (!config->quiet) {
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
printf("%s", alpm_pkg_get_name(pkg));
}
/* print the package size with the output if ShowSize option set */ /* print the package size with the output if ShowSize option set */
if(config->showsize) { if(config->showsize) {
@ -156,6 +160,8 @@ static int query_search(alpm_list_t *targets)
printf(" [%.2f MB]", mbsize); printf(" [%.2f MB]", mbsize);
} }
if (!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp); group = alpm_list_getdata(grp);
printf(" (%s)", (char *)alpm_list_getdata(grp)); printf(" (%s)", (char *)alpm_list_getdata(grp));
@ -164,6 +170,7 @@ static int query_search(alpm_list_t *targets)
/* we need a newline and initial indent first */ /* we need a newline and initial indent first */
printf("\n "); printf("\n ");
indentprint(alpm_pkg_get_desc(pkg), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
}
printf("\n"); printf("\n");
} }
@ -307,7 +314,11 @@ static void display(pmpkg_t *pkg)
dump_pkg_changelog(changelog, alpm_pkg_get_name(pkg)); dump_pkg_changelog(changelog, alpm_pkg_get_name(pkg));
} }
if(!config->op_q_info && !config->op_q_list && !config->op_q_changelog) { if(!config->op_q_info && !config->op_q_list && !config->op_q_changelog) {
if (!config->quiet) {
printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
printf("%s\n", alpm_pkg_get_name(pkg));
}
} }
} }

View file

@ -262,8 +262,12 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *grp; alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(j); pmpkg_t *pkg = alpm_list_getdata(j);
if (!config->quiet) {
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg), printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg)); alpm_pkg_get_version(pkg));
} else {
printf("%s", alpm_pkg_get_name(pkg));
}
/* print the package size with the output if ShowSize option set */ /* print the package size with the output if ShowSize option set */
if(config->showsize) { if(config->showsize) {
@ -273,6 +277,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
printf(" [%.2f MB]", mbsize); printf(" [%.2f MB]", mbsize);
} }
if (!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
group = alpm_list_getdata(grp); group = alpm_list_getdata(grp);
printf(" (%s)", (char *)alpm_list_getdata(grp)); printf(" (%s)", (char *)alpm_list_getdata(grp));
@ -281,6 +286,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
/* we need a newline and initial indent first */ /* we need a newline and initial indent first */
printf("\n "); printf("\n ");
indentprint(alpm_pkg_get_desc(pkg), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
}
printf("\n"); printf("\n");
} }
/* we only want to free if the list was a search list */ /* we only want to free if the list was a search list */
@ -448,8 +454,12 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) { for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
pmpkg_t *pkg = alpm_list_getdata(j); pmpkg_t *pkg = alpm_list_getdata(j);
if (!config->quiet) {
printf("%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg), printf("%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg)); alpm_pkg_get_version(pkg));
} else {
printf("%s\n", alpm_pkg_get_name(pkg));
}
} }
} }