[ADD] -O3, -C [config] flag

This commit is contained in:
LDA 2024-08-19 14:51:34 +02:00
commit 6cd3df21db
2 changed files with 31 additions and 15 deletions

View file

@ -29,22 +29,26 @@ ParseeUptime(void)
static const Argument arguments[] =
{
#define Argument(c, req, vdesc, desc) \
#define Arg(c, req, vdesc, desc) \
{ \
.end = false, \
.argument = c, .value_req = req, \
.value_descr = vdesc, \
.description = desc \
},
#define EndOfArgs { .end = true }
Argument('H', true, "number", "Sets the number of HTTP threads")
Argument('J', true, "number", "Sets the number of XMPP threads")
Arg('H', true, "number(=8)", "Sets the number of HTTP threads")
Arg('J', true, "number(=8)", "Sets the number of XMPP threads")
Arg('C', true, "file(='parsee.json')", "Sets the JSON config to use")
Argument('g',false,NULL,"Generates a parsee.yaml AS file before exiting")
Argument('v',false,NULL,"Forces Parsee to print in a more verbose fashion")
Argument('h',false,NULL,"Generates an help screen(this one!)")
Arg('g', false, NULL,"Generates a parsee.yaml AS file before exiting")
Arg('v', false, NULL,"Forces Parsee to print in a more verbose fashion")
Arg('h', false, NULL,"Generates an help screen(this one!)")
{ .end = true }
EndOfArgs
#undef EndOfArgs
#undef Argument
};
@ -56,6 +60,10 @@ Main(Array *args, HashMap *env)
Stream *yaml;
Cron *cron = NULL;
char *configuration = "parsee.json";
int xmpp = 8;
int http = 8;
start = UtilTsMillis();
memset(&conf, 0, sizeof(conf));
@ -66,16 +74,10 @@ Main(Array *args, HashMap *env)
Log(LOG_INFO, "=======================");
LogConfigIndent(LogConfigGlobal());
ParseeConfigLoad("parsee.json");
ParseeConfigInit();
parsee_conf = ParseeConfigGet();
{
ArgParseState state;
char *opts = ParseeGenerateGetopt(arguments);
int flag;
int xmpp = 8;
int http = 8;
ArgParseStateInit(&state);
/* TODO: Have a smarter way of generating the arg table
@ -105,6 +107,15 @@ Main(Array *args, HashMap *env)
case 'v':
LogConfigLevelSet(LogConfigGlobal(), LOG_DEBUG);
break;
case 'C':
if (!UtilLastModified(state.optArg))
{
Log(LOG_ERR, "Invalid config: %s", state.optArg);
Log(LOG_ERR, "Ignoring.");
break;
}
configuration = state.optArg;
break;
case '?':
Log(LOG_ERR, "INVALID ARGUMENT GIVEN");
Free(opts);
@ -115,6 +126,11 @@ Main(Array *args, HashMap *env)
ParseeSetThreads(xmpp, http);
}
ParseeConfigLoad(configuration);
ParseeConfigInit();
parsee_conf = ParseeConfigGet();
Log(LOG_NOTICE, "Connecting to XMPP...");
jabber = XMPPInitialiseCompStream(
parsee_conf->component_host,