3 #include <rpm/rpmcli.h>
4 #include <rpm/rpmbuild.h>
5 #include <rpm/rpmlog.h>
14 MODE_QUERY = (1 << 0),
15 MODE_PARSE = (1 << 1),
18 static int mode = MODE_UNKNOWN;
19 static int source = RPMQV_SPECRPMS;
20 const char *target = NULL;
21 char *queryformat = NULL;
23 static struct poptOption specOptsTable[] = {
24 { "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
25 N_("parse spec file(s) to stdout"), NULL },
26 { "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
27 N_("query spec file(s)"), NULL },
28 { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
29 N_("operate on binary rpms generated by spec (default)"), NULL },
30 { "builtrpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECBUILTRPMS,
31 N_("operate on binary rpms that would be built from spec"), NULL },
32 { "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
33 N_("operate on source rpm generated by spec"), NULL },
34 { "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
35 N_("use the following query format"), "QUERYFORMAT" },
36 { "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
41 /* the structure describing the options we take and the defaults */
42 static struct poptOption optionsTable[] = {
43 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
44 N_("Spec options:"), NULL },
46 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
47 N_("Common options for all rpm modes and executables:"), NULL },
54 int main(int argc, char *argv[])
57 QVA_t qva = &rpmQVKArgs;
62 xsetprogname(argv[0]); /* Portability call -- see system.h */
64 optCon = rpmcliInit(argc, argv, optionsTable);
66 if (rpmcliPipeOutput && initPipe())
72 rpmReadConfigFiles(rpmcliRcfile, target);
79 if (!poptPeekArg(optCon))
80 argerror(_("no arguments given for query"));
82 qva->qva_queryFormat = queryformat;
83 qva->qva_source = source;
84 qva->qva_specQuery = rpmspecQuery;
85 ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
90 if (!poptPeekArg(optCon))
91 argerror(_("no arguments given for parse"));
93 while ((spath = poptGetArg(optCon)) != NULL) {
94 rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
99 fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
106 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
107 printUsage(optCon, stderr, 0);
117 free(qva->qva_queryFormat);