aboutsummaryrefslogtreecommitdiff
path: root/src/cli.c
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-06-08 22:00:43 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-06-08 22:00:43 +0200
commit81757c235ff8e112b4baabdd1ff23409426e9c98 (patch)
treeef213566ac3c17bf3d7795b0597f254791bd219e /src/cli.c
downloaddwmblocks-async-81757c235ff8e112b4baabdd1ff23409426e9c98.tar.gz
dwmblocks-async-81757c235ff8e112b4baabdd1ff23409426e9c98.tar.bz2
dwmblocks-async-81757c235ff8e112b4baabdd1ff23409426e9c98.zip
update
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/cli.c b/src/cli.c
new file mode 100644
index 0000000..b1849ec
--- /dev/null
+++ b/src/cli.c
@@ -0,0 +1,33 @@
+#include "cli.h"
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+cli_arguments cli_parse_arguments(const char *const argv[], const int argc) {
+ errno = 0;
+ cli_arguments args = {
+ .is_debug_mode = false,
+ };
+
+ int opt = -1;
+ opterr = 0; // Suppress getopt's built-in invalid opt message
+ while ((opt = getopt(argc, (char *const *)argv, "dh")) != -1) {
+ switch (opt) {
+ case 'd':
+ args.is_debug_mode = true;
+ break;
+ case '?':
+ (void)fprintf(stderr, "error: unknown option `-%c'\n", optopt);
+ // fall through
+ case 'h':
+ // fall through
+ default:
+ (void)fprintf(stderr, "usage: %s [-d]\n", BINARY);
+ errno = 1;
+ }
+ }
+
+ return args;
+}