2021-01-25 00:24:31 +01:00
|
|
|
#include "../librepomgr/serversetup.h"
|
|
|
|
|
|
|
|
#include "../libpkg/data/config.h"
|
|
|
|
|
|
|
|
#include "resources/config.h"
|
|
|
|
|
|
|
|
#include <c++utilities/application/argumentparser.h>
|
|
|
|
|
|
|
|
using namespace CppUtilities;
|
|
|
|
using namespace LibRepoMgr;
|
|
|
|
using namespace LibPkg;
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[])
|
|
|
|
{
|
|
|
|
SET_APPLICATION_INFO;
|
|
|
|
|
|
|
|
// define default server setup
|
2022-03-01 00:39:50 +01:00
|
|
|
auto exitCode = 0;
|
|
|
|
auto setup = ServiceSetup();
|
2021-01-25 00:24:31 +01:00
|
|
|
|
|
|
|
// read cli args
|
|
|
|
ArgumentParser parser;
|
|
|
|
OperationArgument runArg("run", 'r', "runs the server");
|
|
|
|
ConfigValueArgument configFileArg("config-file", 'c', "specifies the path of the config file", { "path" });
|
|
|
|
configFileArg.setEnvironmentVariable(PROJECT_VARNAME_UPPER "_CONFIG_FILE");
|
2022-01-25 00:13:10 +01:00
|
|
|
ConfigValueArgument forceLoadingDBsArg("force-loading-dbs", 'f', "forces loading DBs, even if DB files have not been modified since last parse");
|
|
|
|
runArg.setSubArguments({ &configFileArg, &forceLoadingDBsArg });
|
2021-01-25 00:24:31 +01:00
|
|
|
runArg.setImplicit(true);
|
2022-03-01 00:39:50 +01:00
|
|
|
runArg.setCallback([&setup, &exitCode, &configFileArg, &forceLoadingDBsArg](const ArgumentOccurrence &) {
|
2022-01-25 00:13:10 +01:00
|
|
|
if (const auto configFilePath = configFileArg.firstValue()) {
|
|
|
|
setup.configFilePath = configFilePath;
|
2021-01-25 00:24:31 +01:00
|
|
|
}
|
2022-01-25 00:13:10 +01:00
|
|
|
setup.building.forceLoadingDbs = forceLoadingDBsArg.isPresent();
|
2022-03-01 00:39:50 +01:00
|
|
|
exitCode = setup.run();
|
2021-01-25 00:24:31 +01:00
|
|
|
});
|
2022-03-07 23:36:48 +01:00
|
|
|
OperationArgument fixDb("fix-db", '\0', "fixes the database files");
|
|
|
|
fixDb.setSubArguments({ &configFileArg });
|
|
|
|
fixDb.setCallback([&setup, &exitCode, &configFileArg](const ArgumentOccurrence &) {
|
|
|
|
if (const auto configFilePath = configFileArg.firstValue()) {
|
|
|
|
setup.configFilePath = configFilePath;
|
|
|
|
}
|
|
|
|
exitCode = setup.fixDb();
|
|
|
|
});
|
2023-12-16 22:13:44 +01:00
|
|
|
OperationArgument dumpDb("dump-db", '\0', "dumps package database entries");
|
|
|
|
ConfigValueArgument filterRegexArg("filter-regex", 'r', "dump only packages which name matches the specified regex", { "regex" });
|
|
|
|
dumpDb.setSubArguments({ &filterRegexArg, &configFileArg });
|
|
|
|
dumpDb.setCallback([&setup, &exitCode, &filterRegexArg, &configFileArg](const ArgumentOccurrence &) {
|
|
|
|
if (const auto configFilePath = configFileArg.firstValue()) {
|
|
|
|
setup.configFilePath = configFilePath;
|
|
|
|
}
|
|
|
|
exitCode = setup.dumpDb(filterRegexArg.isPresent() ? std::string_view(filterRegexArg.firstValue()) : std::string_view());
|
|
|
|
});
|
2021-01-25 00:24:31 +01:00
|
|
|
HelpArgument helpArg(parser);
|
|
|
|
NoColorArgument noColorArg;
|
2023-12-16 22:13:44 +01:00
|
|
|
parser.setMainArguments({ &runArg, &fixDb, &dumpDb, &noColorArg, &helpArg });
|
2021-01-25 00:24:31 +01:00
|
|
|
parser.setDefaultArgument(&runArg);
|
|
|
|
parser.parseArgs(argc, argv);
|
2022-03-01 00:39:50 +01:00
|
|
|
return exitCode;
|
2021-01-25 00:24:31 +01:00
|
|
|
}
|