aboutsummaryrefslogtreecommitdiff
path: root/src/args.c
blob: 7962ad41967299158dc57ddc6c2fdd12cb46bab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "args.h"

#include "stdbool.h"
#include "stdio.h"
#include "string.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;

  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 (strcmp(arg, "--help") == 0) {
      flags |= POW_FLAG_HELP;

      continue;
    }

    if (strcmp(arg, "-c") == 0) {
      next_flag_config = true;

      continue;
    }
  }

  if (next_flag_config) {
    printf("Missing argument for -c\n");
  }

  args->flags = flags;

  return 0;
}

void pow_args_print_help() { printf("%s", help); };