summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/client/Jamfile.jam5
-rw-r--r--gentoobrowse-api/client/main.cpp51
-rw-r--r--gentoobrowse-api/client/main.h15
-rw-r--r--gentoobrowse-api/client/search.cpp24
4 files changed, 76 insertions, 19 deletions
diff --git a/gentoobrowse-api/client/Jamfile.jam b/gentoobrowse-api/client/Jamfile.jam
index 66165d9..7c3edaa 100644
--- a/gentoobrowse-api/client/Jamfile.jam
+++ b/gentoobrowse-api/client/Jamfile.jam
@@ -1,7 +1,12 @@
+lib boost_program_options ;
+
exe gbcli :
[ glob *.cpp ]
:
<library>../domain//gentoobrowse-domain
+ <library>..//adhocutil
+ <library>..//boost_system
+ <library>boost_program_options
<implicit-dependency>../domain//gentoobrowse-domain
<library>../api//gentoobrowse-api
<implicit-dependency>../api//gentoobrowse-api
diff --git a/gentoobrowse-api/client/main.cpp b/gentoobrowse-api/client/main.cpp
index 61c6575..d2f70bb 100644
--- a/gentoobrowse-api/client/main.cpp
+++ b/gentoobrowse-api/client/main.cpp
@@ -1,30 +1,43 @@
#include "stdio.h"
+#include "main.h"
#include <portage.h>
+#include <plugins.impl.h>
#include <Ice/Ice.h>
+#include <boost/program_options.hpp>
+
+namespace po = boost::program_options;
+INSTANTIATEPLUGINOF(Module);
int
main(int c, char ** v)
{
- auto ic = Ice::initialize(c, v);
- auto p = Gentoo::PortagePrx::checkedCast(ic->stringToProxy("portage:tcp -h localhost -p 9001"));
-#if 0
- for (int x = 1; x < c; x += 1) {
- auto cat = p->getCategory(atoi(v[x]));
- fprintf(stdout, "%d: %s\n", cat->categoryid, cat->name.c_str());
- if (cat->summary) {
- fprintf(stdout, "\t%s\n", cat->summary->c_str());
- }
- fprintf(stdout, "\n");
- }
- auto ps = p->getPackagesSearch(v[1]);
- for (const auto & p : ps) {
- fprintf(stderr, "%d / %s\n\t%s\n", p->categoryid, p->name.c_str(), p->description.c_str());
- }
-#endif
- auto fp = p->findPackage(v[1], v[2]);
- if (fp) {
- fprintf(stderr, "%d / %s\n\t%s\n", (*fp)->categoryid, (*fp)->name.c_str(), (*fp)->description.c_str());
+ std::string endpoint;
+ std::string module;
+ std::vector<std::string> args;
+ po::options_description opts("Gentoo Browse Client options");
+ opts.add_options()
+ ("endpoint", po::value(&endpoint)->default_value("tcp -h gentoobrowse.randomdan.homeip.net -p 9001"), "Service endpoint")
+ ("module", po::value(&module), "Module")
+ ("args", po::value(&args), "Module options")
+ ("help,h", "Show help")
+ ;
+ po::positional_options_description pod;
+ pod.add("module", 1).add("args", -1);
+ po::variables_map vm;
+ po::store(po::command_line_parser(c, v).options(opts).positional(pod).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cerr << opts << std::endl;
+ exit(1);
}
+
+ auto ic = Ice::initialize(c, v);
+ auto p = Gentoo::PortagePrx::checkedCast(ic->stringToProxy("portage:" + endpoint));
+ p->ice_ping();
+
+ AdHoc::PluginManager::getDefault()->get<Module>(module)->implementation()->run(p, args);
+
ic->destroy();
return 0;
}
diff --git a/gentoobrowse-api/client/main.h b/gentoobrowse-api/client/main.h
new file mode 100644
index 0000000..9c7c9f7
--- /dev/null
+++ b/gentoobrowse-api/client/main.h
@@ -0,0 +1,15 @@
+#ifndef GENTOO_MAIN_H
+#define GENTOO_MAIN_H
+
+#include <vector>
+#include <string>
+#include <plugins.h>
+#include <portage.h>
+
+class Module : public AdHoc::AbstractPluginImplementation {
+ public:
+ virtual void run(Gentoo::PortagePrx, const std::vector<std::string> &) const = 0;
+};
+
+#endif
+
diff --git a/gentoobrowse-api/client/search.cpp b/gentoobrowse-api/client/search.cpp
new file mode 100644
index 0000000..dd4baf1
--- /dev/null
+++ b/gentoobrowse-api/client/search.cpp
@@ -0,0 +1,24 @@
+#include <plugins.h>
+#include <fprintbf.h>
+#include <boost/algorithm/string/join.hpp>
+#include "main.h"
+
+class search : public Module {
+ public:
+ void run(Gentoo::PortagePrx p, const std::vector<std::string> & a) const override
+ {
+ auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " "));
+ std::map<int, Gentoo::CategoryPtr> cats;
+ fprintbf(stdout, "Found %d packages:\n", pkgs.size());
+ for (const auto & pkg : pkgs) {
+ auto ci = cats.find(pkg->categoryid);
+ if (ci == cats.end()) {
+ ci = cats.insert({pkg->categoryid, p->getCategory(pkg->categoryid)}).first;
+ }
+ fprintbf(stdout, "%s / %s\n\t%s\n", ci->second->name, pkg->name, pkg->description);
+ }
+ }
+};
+
+PLUGIN(search, Module);
+