]> git.ayabusa.dev Git - thoryum.git/commitdiff
good enough arg parser
authorAyabusa <lebgpub@gmail.com>
Sun, 7 Jun 2026 19:40:54 +0000 (21:40 +0200)
committerAyabusa <lebgpub@gmail.com>
Sun, 7 Jun 2026 19:40:54 +0000 (21:40 +0200)
Makefile
src/cli.c
src/cli.h
src/cli.o [deleted file]
src/main.c

index 262a9eb82d965f2d2dceb8c57bf187998482ab4d..9faa0d09ca9792a2303e0760d5f187f58ca95a37 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CFLAGS = -Wall -Wextra -g
 LIBS = -lcurl
 SRC = src/main.c src/cpu.c src/downloader.c src/cli.c
-OBJ = build/main.o build/cpu.o build/downloader.o src/cli.o
+OBJ = build/main.o build/cpu.o build/downloader.o build/cli.o
 RES = build/Thoryum
 
 all: setup $(OBJ) build
index 083bf2c68066659fba24696173c74206679623e6..5643c76ca000dc7a5f47218d4be32b778eb30db3 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -5,8 +5,19 @@
 #include "cli.h"
 
 extern char *optarg; // What the hell is that glibc ???
+extern int optind, opterr, optopt;
+
+void check_help(int argc, char **argv) {
+    for (int i = 1; i < argc; i++)
+        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
+            print_help();
+            exit(EXIT_SUCCESS);
+        }
+}
 
 struct ctx *init_ctx(int argc, char **argv) {
+    check_help(argc, argv);
+
     struct ctx *ctx = calloc(1, sizeof(struct ctx));
     int opt;
 
@@ -39,6 +50,18 @@ void *free_ctx(struct ctx *ctx) {
     return NULL;
 }
 
+void print_ctx(struct ctx *ctx) {
+    printf(
+        "Thoryum context:\n"
+        "Mode = %s\n"
+        "Install location = '%s'\n"
+        "Silent = %s\n",
+        ctx->mode ? "UPDATE" : "NORMAL",
+        ctx->install_loc,
+        ctx->silent ? "YES" : "NOPE"
+    );
+}
+
 void print_help() {
     printf(
     "Usage: thoryum [options]\n"
index 9647c1055e2c45898d21ae9b4f9eea43f9020b32..8a36ff2c748076627c019ee8ed6bb9dee7ec12b6 100644 (file)
--- a/src/cli.h
+++ b/src/cli.h
@@ -12,6 +12,9 @@ struct ctx {
     int silent;
 };
 
+struct ctx *init_ctx(int argc, char **argv);
+void *free_ctx(struct ctx *ctx);
+void print_ctx(struct ctx *ctx);
 void print_help();
 
 #endif
diff --git a/src/cli.o b/src/cli.o
deleted file mode 100644 (file)
index 48003b7..0000000
Binary files a/src/cli.o and /dev/null differ
index 62bafe989f8115e8b1e57a34e06690d83e8aac84..42bf73c6fb6ee86f9fe50ef73144de7f7c99bd9e 100644 (file)
@@ -34,7 +34,7 @@ void patch_desktop_file(char *install_loc) {
     wait(NULL);
 }
 
-int main() {
+int main(int argc, char **argv) {
        printf("Hello this is Thoryum ;)\n");
        enum CPU_opti opti = CPU_fetch_opti();
        char opti_name[5] = {0};
@@ -47,5 +47,7 @@ int main() {
        */
        //printf("Latest version url : '%s,'\n",DL_get_latest_version_url("AVX.zip"));
        //patch_desktop_file(".");
-       print_help();
+       struct ctx *ctx = init_ctx(argc, argv);
+       print_ctx(ctx);
+       ctx = free_ctx(ctx);
 }