summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Bowes <jbowes@redhat.com>2008-06-26 19:11:36 -0400
committerJames Bowes <jbowes@redhat.com>2008-06-26 19:11:36 -0400
commit9795b68febdde5a3077009ef69e8e20abdf77d82 (patch)
tree88fad16cd3a946754292d542f8ddcc767bbc9273
parente85c7b8eac548a22e523c3e746d07b5fda72c726 (diff)
Add 'search' command
-rw-r--r--src/main.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index c2ecd6e..4532f02 100644
--- a/src/main.c
+++ b/src/main.c
@@ -860,6 +860,52 @@ command_info(int argc, const char *argv[])
return 0;
}
+#define SEARCH_MAX 256
+
+static int
+command_search(int argc, const char *argv[])
+{
+ struct razor_set *set;
+ struct razor_package_iterator *pi;
+ struct razor_package *package;
+ char pattern[SEARCH_MAX];
+ const char *name, *version, *arch;
+ const char *summary, *description, *url, *license;
+
+ if (!argv[0]) {
+ fprintf(stderr, "must specify a search term\n");
+ return 1;
+ }
+
+ sprintf(pattern, "*%s*", argv[0]);
+
+ set = razor_set_open(repo_filename);
+ if (set == NULL)
+ return 1;
+ if (razor_set_open_details(set, "system-details.repo"))
+ return 1;
+
+ pi = razor_package_iterator_create(set);
+ while (razor_package_iterator_next(pi, &package,
+ &name, &version, &arch)) {
+ if (!fnmatch(pattern, name, 0))
+ printf("%s-%s.%s\n", name, version, arch);
+ else {
+ razor_package_get_details (set, package, &summary,
+ &description, &url,
+ &license);
+ if (!fnmatch(pattern, url, 0) ||
+ !fnmatch(pattern, summary, 0) ||
+ !fnmatch(pattern, description, 0))
+ printf("%s-%s.%s\n", name, version, arch);
+ }
+ }
+ razor_package_iterator_destroy(pi);
+ razor_set_destroy(set);
+
+ return 0;
+}
+
static struct {
const char *name;
const char *description;
@@ -884,7 +930,8 @@ static struct {
{ "install", "install rpm", command_install },
{ "init", "init razor root", command_init },
{ "download", "download packages", command_download },
- { "info", "display package details", command_info }
+ { "info", "display package details", command_info },
+ { "search", "search package details", command_search }
};
static int