63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
|
#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
|
||
|
helpers_parse_cli(int argc, const char **argv, config_t *config)
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
LOG_FATAL("bad action '%s' given ('start', 'test')", argv[0]);
|
||
|
exit(1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
LOG_FATAL("no action given ('start', 'test')");
|
||
|
exit(1);
|
||
|
}
|
||
|
return;
|
||
|
}
|