From 8fbd1abcda5d5fa030fdceca3aa66d1ffa74c26d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 27 Sep 2025 11:13:25 +0000 Subject: [PATCH] daemon: Parse command line options Signed-off-by: Michael Tremer --- src/daemon/main.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index 01e1a78..bf8246c 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -18,13 +18,49 @@ # # #############################################################################*/ +#include #include #include +#include #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 @@ -32,7 +68,10 @@ int main(int argc, char* argv[]) { 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) -- 2.47.3