[ADD] Help screen

This commit is contained in:
LDA 2024-08-19 11:40:29 +02:00
commit 4b2ede6a66
3 changed files with 102 additions and 1 deletions

View file

@ -27,6 +27,27 @@ ParseeUptime(void)
return UtilTsMillis() - start;
}
static const Argument arguments[] =
{
#define Argument(c, req, vdesc, desc) \
{ \
.end = false, \
.argument = c, .value_req = req, \
.value_descr = vdesc, \
.description = desc \
},
Argument('H', true, "number", "Sets the number of HTTP threads")
Argument('J', true, "number", "Sets the number of XMPP threads")
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!)")
{ .end = true }
#undef Argument
};
int
Main(Array *args, HashMap *env)
{
@ -51,6 +72,7 @@ Main(Array *args, HashMap *env)
{
ArgParseState state;
char *opts = ParseeGenerateGetopt(arguments);
int flag;
int xmpp = 8;
int http = 8;
@ -58,10 +80,14 @@ Main(Array *args, HashMap *env)
ArgParseStateInit(&state);
/* TODO: Have a smarter way of generating the arg table
* (with a list of structs, with a description and everything) */
while ((flag = ArgParse(&state, args, "vgH:J:")) != -1)
while ((flag = ArgParse(&state, args, opts)) != -1)
{
switch (flag)
{
case 'h':
ParseeGenerateHelp(arguments);
Free(opts);
goto end;
case 'H':
http = strtol(state.optArg, NULL, 10);
break;
@ -74,15 +100,18 @@ Main(Array *args, HashMap *env)
yaml = StreamOpen("parsee.yaml", "w");
ParseeExportConfigYAML(yaml);
StreamClose(yaml);
Free(opts);
goto end;
case 'v':
LogConfigLevelSet(LogConfigGlobal(), LOG_DEBUG);
break;
case '?':
Log(LOG_ERR, "INVALID ARGUMENT GIVEN");
Free(opts);
goto end;
}
}
Free(opts);
ParseeSetThreads(xmpp, http);
}