2020-04-17 23:24:36 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <argparse.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <logger.h>
|
|
|
|
#include <helpers.h>
|
|
|
|
|
|
|
|
static const char *const usage[] = {
|
|
|
|
"controller [options] [[--] args]",
|
|
|
|
"controller [options]",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PERM_READ (1<<0)
|
|
|
|
#define PERM_WRITE (1<<1)
|
|
|
|
#define PERM_EXEC (1<<2)
|
|
|
|
|
|
|
|
void
|
2020-04-24 22:48:59 +00:00
|
|
|
helper_parse_cli(int argc, const char **argv, config_t *config)
|
2020-04-17 23:24:36 +00:00
|
|
|
{
|
|
|
|
struct argparse_option options[] =
|
|
|
|
{
|
|
|
|
OPT_HELP(),
|
|
|
|
OPT_GROUP("Basic options"),
|
|
|
|
OPT_STRING('c', "config", &config->file, "path to config file", NULL, 0, OPT_NONEG),
|
|
|
|
|
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
|
|
|
struct argparse argparse;
|
|
|
|
argparse_init(&argparse, options, usage, 0);
|
|
|
|
argparse_describe(
|
|
|
|
&argparse,
|
|
|
|
"\nA brief description of what the program does and how it works.",
|
|
|
|
"\nAdditional description of the program after the description of the arguments."
|
|
|
|
);
|
|
|
|
argc = argparse_parse(&argparse, argc, argv);
|
|
|
|
|
|
|
|
if(argc == 1)
|
|
|
|
{
|
|
|
|
if(strcmp(argv[0], "start") == 0)
|
|
|
|
{
|
|
|
|
config->run_type = RUN_TYPE_START;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(strcmp(argv[0], "test") == 0)
|
|
|
|
{
|
|
|
|
config->run_type = RUN_TYPE_TEST;
|
|
|
|
return;
|
|
|
|
}
|
2020-04-24 13:08:26 +00:00
|
|
|
LOG_FATAL("bad action '%s' given ('start', 'test')\n", argv[0]);
|
2020-04-17 23:24:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-24 13:08:26 +00:00
|
|
|
LOG_FATAL("no action given ('start', 'test')\n");
|
2020-04-17 23:24:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|