]> git.ayabusa.dev Git - thoryum.git/commitdiff
Added some context and cli stuff
authorAyabusa <lebgpub@gmail.com>
Sun, 7 Jun 2026 19:21:33 +0000 (21:21 +0200)
committerAyabusa <lebgpub@gmail.com>
Sun, 7 Jun 2026 19:21:33 +0000 (21:21 +0200)
src/cli.c
src/cli.h

index 56b8552cc2e79a6220ab7dbd1282671272adfbfb..083bf2c68066659fba24696173c74206679623e6 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1,10 +1,42 @@
-#include "cli.h"
+#include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+#include "cli.h"
+
+extern char *optarg; // What the hell is that glibc ???
 
 struct ctx *init_ctx(int argc, char **argv) {
-    struct ctx *ctx = malloc(sizeof(struct ctx));
+    struct ctx *ctx = calloc(1, sizeof(struct ctx));
+    int opt;
+
+    while ((opt = getopt(argc, argv, "yul:")) != -1) {
+        switch (opt) {
+        case 'y':
+            ctx->silent = 1;
+            break;
+        case 'u':
+            ctx->mode = UPDATE;
+            break;
+        case 'l':
+            ctx->install_loc = strdup(optarg);
+            break;
+        default: // bozo
+            fprintf(stderr, "Usage: %s [-h] [-u] [-y] [-l path]\n",
+                    argv[0]);
+            free(ctx);
+            exit(EXIT_FAILURE);
+        }
+    }
+    if (!ctx->install_loc)
+        ctx->install_loc = strdup("/usr/bin");
+    return ctx;
+}
 
+void *free_ctx(struct ctx *ctx) {
+    free(ctx->install_loc);
+    free(ctx);
+    return NULL;
 }
 
 void print_help() {
@@ -13,13 +45,13 @@ void print_help() {
     "Thoryum is an install helper, and update wrapper for the Thorium browser.\n"
     "\n"
     "Options:\n"
-    "  -h, --help\n"
+    "  -h\n"
     "      Print this help message.\n"
     "\n"
-    "  -l, --location <path>\n"
+    "  -l <path>\n"
     "      Install Thorium to a specific path, default is '/usr/bin'.\n"
     "\n"
-    "  -y, --yes\n"
+    "  -y\n"
     "      Do not ask for confirmation and apply the install directly.\n"
     "\n"
     "  -u [DO NOT USE !!!]\n"
index 48932245a5b3cf283e7a72e99ccf79a408829a0d..9647c1055e2c45898d21ae9b4f9eea43f9020b32 100644 (file)
--- a/src/cli.h
+++ b/src/cli.h
@@ -2,14 +2,14 @@
 #define CLI_H
 
 enum mode {
-    HELP,
+    NORMAL = 0,
     UPDATE,
-    NORMAL,
 };
 
 struct ctx {
     enum mode mode;
     char *install_loc;
+    int silent;
 };
 
 void print_help();