# #
#############################################################################*/
+#include <argp.h>
#include <stddef.h>
#include <stdlib.h>
+#include <syslog.h>
#include "ctx.h"
+const char* argp_program_version = PACKAGE_VERSION;
+
+static const char* doc = "The collecty Daemon";
+
+enum {
+ OPT_DEBUG = 1,
+};
+
+static struct argp_option options[] = {
+ { "debug", OPT_DEBUG, NULL, 0, "Run in debug mode", 0 },
+ { NULL },
+};
+
+static error_t parse(int key, char* arg, struct argp_state* state) {
+ collecty_ctx* ctx = state->input;
+
+ switch (key) {
+ case OPT_DEBUG:
+ collecty_ctx_set_log_level(ctx, LOG_DEBUG);
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
int main(int argc, char* argv[]) {
collecty_ctx* ctx = NULL;
+ struct argp parser = {
+ .options = options,
+ .parser = parse,
+ .doc = doc,
+ };
+ int arg_index = 0;
int r;
// Allocate a new context
if (r < 0)
goto ERROR;
- // TODO
+ // Parse command line arguments
+ r = argp_parse(&parser, argc, argv, ARGP_NO_ARGS, &arg_index, &ctx);
+ if (r)
+ goto ERROR;
ERROR:
if (ctx)