#include "args.h" #include "stdbool.h" #include "stdio.h" #include "string.h" #include "utils.h" char *help = "▄▄▄▄▄▄▄▄▄▄▄ ▄\n" "█ █ █ ▄ █\n" "█▄▄▄▄█▄▄▄▄█▄▄█▄▄█\n" "█\n\n" "pow! - the pow!erful package manager\n" "Made with love by forever2k38\n" "Source code at: https://codeberg.org/einfach/pow\n" "Use outside of einfach is unsupported.\n" "This software comes with no warranty.\n" "\n" "Usage: pow\n" " --help Prints this help message.\n" " -c Specify config file path.\n"; int pow_args_parse(int argc, char **argv, pow_args *args) { int flags = 0; bool next_flag_config; bool next_flag_package; for (int i = 0; i < argc; i++) { char *arg = argv[i]; if (next_flag_config) { if (!strncmp(arg, "-", sizeof("-") - 1)) { printf("Missing argument for -c\n"); return 1; } args->cfg_path = arg; next_flag_config = false; continue; } if (next_flag_package) { if (!strncmp(arg, "-", sizeof("-") - 1)) { printf("Missing package argument\n"); return 1; } args->package = arg; next_flag_package = false; continue; } if (strcmp(arg, "--help") == 0) { flags |= POW_FLAG_HELP; continue; } if (strcmp(arg, "-c") == 0) { next_flag_config = true; continue; } if (string_has_prefix("-", arg)) { size_t len = strlen(arg); for (size_t j = 0; j < len; j++) { char c = (char)arg[j]; switch (c) { case 'S': { if (flags & POW_FLAG_SYNC) { printf("flag double defined, skipping\n"); } flags |= POW_FLAG_SYNC; next_flag_package = true; }; case 'Q': { if (flags & POW_FLAG_QUERY) { printf("flag double defined, skipping\n"); } flags |= POW_FLAG_QUERY; next_flag_package = true; } } } continue; } } if (next_flag_config) { printf("Missing argument for -c\n"); } if (!args->cfg_path) args->cfg_path = DEFAULT_CONFIG_PATH; args->flags = flags; return 0; } void pow_args_print_help() { printf("%s", help); };