-#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() {
"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"