commit caf60dee3d5c193e4128ec7393c2e6a03bb0865d
parent 0c3f2d414a7ff26475d4dde531bef52fddba890a
Author: Yersa Nordman <yersa@finwo.nl>
Date: Tue, 31 Jan 2023 23:40:13 +0100
Implemented basic argument parsing
Diffstat:
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -20,7 +20,7 @@ BIN=pmlag
default: $(BIN) $(BIN).1 README.md
%.o: %.c $(LIBS)
- $(CC) $(CFLAGS) $(@:.o=.c) -c -o $@
+ $(CC) $(CFLAGS) $(@:.o=.c) -D__NAME=\"$(BIN)\" -c -o $@
$(BIN): $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $@
diff --git a/package.ini b/package.ini
@@ -1,5 +1,6 @@
[dependencies]
benhoyt/inih=https://raw.githubusercontent.com/finwo/dep-repository/main/benhoyt/inih/package-edge.ini
+cofyc/argparse=https://raw.githubusercontent.com/finwo/dep-repository/main/cofyc/argparse/package.ini
[package]
deps=lib
name=finwo/pmlag
diff --git a/src/main.c b/src/main.c
@@ -1,5 +1,34 @@
-#include "benhoyt/inih.h"
+#include "cofyc/argparse.h"
-int main() {
+#include <stdio.h>
+
+static const char *const usage[] = {
+ __NAME " [options]",
+ NULL
+};
+
+int main(int argc, const char **argv) {
+ char *config_file="/etc/pmlag/pmlag.ini";
+
+ // Define which options we support
+ struct argparse_option options[] = {
+ OPT_HELP(),
+ OPT_STRING('c', "config", &config_file, "Config file to use", NULL, 0, 0),
+ OPT_END(),
+ };
+
+ // Parse command line arguments
+ struct argparse argparse;
+ argparse_init(&argparse, options, usage, 0);
+ argparse_describe(&argparse, NULL,
+ // TODO: format to terminal width
+ "\n" __NAME " is a tool for bonding network interfaces together when the "
+ "hardware\non the other side of the cable(s) doesn't support it."
+ "\n"
+ );
+ argc = argparse_parse(&argparse, argc, argv);
+
+ printf("name: %s\n", __NAME);
+ printf("conf: %s\n", config_file);
return 42;
}