From: Ayabusa Date: Sun, 7 Jun 2026 19:21:33 +0000 (+0200) Subject: Added some context and cli stuff X-Git-Url: https://git.ayabusa.dev/?a=commitdiff_plain;h=ba9de9e7eea6d5d28f59e76fdc0c2ea7d8e8b174;p=thoryum.git Added some context and cli stuff --- diff --git a/src/cli.c b/src/cli.c index 56b8552..083bf2c 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1,10 +1,42 @@ -#include "cli.h" +#include #include #include +#include +#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 \n" + " -l \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" diff --git a/src/cli.h b/src/cli.h index 4893224..9647c10 100644 --- 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();