#include "repoindex/alpm/manager.h" #include "repoindex/alpm/utilities.h" #include "repoindex/alpm/config.h" #include "repoindex/alpm/resolvebuildorder.h" #include "repoindex/alpm/mingwbundle.h" #include "repoindex/network/server.h" #include #include #include #include #include #include using namespace std; using namespace ApplicationUtilities; using namespace RepoIndex; int main(int argc, char *argv[]) { // check whether shell syntax is enabled for(char **arg = argv, **end = argv + argc; arg != end; ++arg) { if(strcmp(*arg, "--sh-syntax") == 0) { useShSyntax = true; shchar = "# "; break; } } // setup the argument parser ArgumentParser parser; ConfigArgs configArgs(parser); parser.setIgnoreUnknownArguments(false); // parse command line arguments try { parser.parseArgs(argc, argv); } catch (Failure &e) { cerr << shchar << "Unable to parse arguments: " << e.what() << endl; return 2; } try { // load configuration Config config; config.loadFromConfigFile(configArgs); config.loadFromArgs(configArgs); if(find_if(parser.mainArguments().cbegin(), parser.mainArguments().cend(), [&configArgs] (const Argument *arg) { return arg != &configArgs.helpArg && arg->isPresent(); }) != parser.mainArguments().cend()) { // create app QCoreApplication application(argc, argv); // setup ALPM Manager manager(config); manager.applyPacmanConfig(); manager.applyRepoIndexConfig(); cerr << shchar << "Loading databases ..." << endl; manager.initAlpmDataBases(); if(configArgs.serverArg.isPresent()) { // setup the server Server server(manager, manager.config()); QObject::connect(&server, &Server::closed, &application, &QCoreApplication::quit); // run Qt loop return application.exec(); } else if(configArgs.buildOrderArg.isPresent()) { BuildOrderResolver resolver(manager); const QStringList results = resolver.resolve(configArgs.buildOrderArg.values()); // print results if(useShSyntax) { cout << "export REPOINDEX_RESULTS=("; for(const auto &pkgName : results) { cout << ' ' << '\'' << pkgName.toLocal8Bit().data() << '\''; } cout << ' ' << ')' << endl; } else { cout << "Results: "; for(const auto &pkgName : results) { cout << pkgName.toLocal8Bit().data() << ' '; } cout << endl; } } else if(configArgs.mingwBundleArg.isPresent()) { MingwBundle bundle(manager, configArgs.mingwBundleArg.values(), configArgs.iconThemesArg.values()); bundle.createBundle(configArgs.targetDirArg.isPresent() ? configArgs.targetDirArg.values().front() : string("."), configArgs.targetNameArg.values().front(), configArgs.targetFormatArg.isPresent() ? configArgs.targetFormatArg.values().front() : string("zip")); } else if(configArgs.upgradeLookupArg.isPresent()) { cerr << shchar << "TODO" << endl; } } else if(!configArgs.helpArg.isPresent()) { if(useShSyntax) { cerr << "export REPOINDEX_ERROR='No command line arguments specified. See --help for available commands.'" << endl; } else { cerr << "No command line arguments specified. See --help for available commands." << endl; } } } catch (std::exception &e) { if(useShSyntax) { string error = e.what(); ConversionUtilities::findAndReplace(error, "'", "\'"); cerr << "export REPOINDEX_ERROR='" << error << '\'' << endl; } else { cerr << shchar << "Error: " << e.what() << endl; } return 1; } }