]> git.ipfire.org Git - pakfire.git/commitdiff
cli: client: Add a --debug switch
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 10:36:04 +0000 (10:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 10:36:04 +0000 (10:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/pakfire-client.c

index 512add58686c56c4c49f73f27e5c65f93e1cecaf..59877d735f9c6c11425605ca26fde986ded55f20 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <argp.h>
+#include <syslog.h>
 
 #include <pakfire/ctx.h>
 
@@ -38,6 +39,30 @@ static const char* args_doc =
 
 static const char* doc = "The Pakfire Build Service Client Tool";
 
+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, void* data) {
+       struct pakfire_ctx* ctx = data;
+
+       switch (key) {
+               case OPT_DEBUG:
+                       pakfire_ctx_set_log_level(ctx, LOG_DEBUG);
+                       break;
+
+               default:
+                       return ARGP_ERR_UNKNOWN;
+       }
+
+       return 0;
+}
+
 int main(int argc, char* argv[]) {
        struct pakfire_ctx* ctx = NULL;
        int r;
@@ -51,7 +76,7 @@ int main(int argc, char* argv[]) {
        pakfire_ctx_set_progress_callback(ctx, cli_setup_progressbar, NULL);
 
        // Parse the command line and run any commands
-       r = cli_parse(NULL, commands, args_doc, doc, NULL, argc, argv, ctx);
+       r = cli_parse(options, commands, args_doc, doc, parse, argc, argv, ctx);
 
 ERROR:
        if (ctx)