Split command line interface out into main.c.
9 static const char *repo_filename = "system.repo";
10 static const char rawhide_repo_filename[] = "rawhide.repo";
13 command_list(int argc, const char *argv[])
15 struct razor_set *set;
17 set = razor_set_open(repo_filename);
19 razor_set_destroy(set);
25 command_list_requires(int argc, const char *argv[])
27 struct razor_set *set;
29 set = razor_set_open(repo_filename);
30 razor_set_list_requires(set, argv[2]);
31 razor_set_destroy(set);
37 command_list_provides(int argc, const char *argv[])
39 struct razor_set *set;
41 set = razor_set_open(repo_filename);
42 razor_set_list_provides(set, argv[2]);
43 razor_set_destroy(set);
49 command_what_requires(int argc, const char *argv[])
51 struct razor_set *set;
53 set = razor_set_open(repo_filename);
54 razor_set_list_requires_packages(set, argv[2], argv[3]);
55 razor_set_destroy(set);
61 command_what_provides(int argc, const char *argv[])
63 struct razor_set *set;
65 set = razor_set_open(repo_filename);
66 razor_set_list_provides_packages(set, argv[2], argv[3]);
67 razor_set_destroy(set);
73 command_import_yum(int argc, const char *argv[])
75 struct razor_set *set;
77 set = razor_set_create_from_yum_filelist(STDIN_FILENO);
80 razor_set_write(set, rawhide_repo_filename);
81 razor_set_destroy(set);
82 printf("wrote %s\n", rawhide_repo_filename);
88 command_import_rpmdb(int argc, const char *argv[])
90 struct razor_set *set;
92 set = razor_set_create_from_rpmdb();
95 razor_set_write(set, repo_filename);
96 razor_set_destroy(set);
97 printf("wrote %s\n", repo_filename);
103 command_validate(int argc, const char *argv[])
105 struct razor_set *set;
107 set = razor_set_open(repo_filename);
110 razor_set_list_unsatisfied(set);
111 razor_set_destroy(set);
117 command_update(int argc, const char *argv[])
119 struct razor_set *set, *upstream;
121 set = razor_set_open(repo_filename);
122 upstream = razor_set_open(rawhide_repo_filename);
123 if (set == NULL || upstream == NULL)
125 set = razor_set_update(set, upstream, argc - 2, argv + 2);
126 razor_set_write(set, "system-updated.repo");
127 razor_set_destroy(set);
128 razor_set_destroy(upstream);
129 printf("wrote system-updated.repo\n");
136 const char *description;
137 int (*func)(int argc, const char *argv[]);
138 } razor_commands[] = {
139 { "list", "list all packages", command_list },
140 { "list-requires", "list all requires or requires for the given package", command_list_requires },
141 { "list-provides", "list all provides or provides for the give package", command_list_provides },
142 { "what-requires", "list the packages that have the given requires", command_what_requires },
143 { "what-provides", "list the packages that have the given provides", command_what_provides },
144 { "import-yum", "import yum filelist.xml on stdin", command_import_yum },
145 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
146 { "validate", "validate a package set", command_validate },
147 { "update", "update all or specified packages", command_update }
156 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
158 razor_commands[i].name, razor_commands[i].description);
164 main(int argc, const char *argv[])
169 repo = getenv("RAZOR_REPO");
171 repo_filename = repo;
176 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
177 if (strcmp(razor_commands[i].name, argv[1]) == 0)
178 return razor_commands[i].func(argc - 2, argv + 2);