moving config parsing before option parsing

This commit is contained in:
jacekpoz 2024-02-11 23:51:42 +01:00
parent c50902e45e
commit 55414046ea
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C

View file

@ -25,6 +25,18 @@ int main(int argc, char *argv[]) {
char *config_path = default_config_path(); char *config_path = default_config_path();
FILE *config_file = fopen(config_path, "r");
if (config_file == NULL) {
fprintf(stderr, "error: failed to open config at: %s\n", config_path);
exit(EXIT_FAILURE);
}
Config config = parse_config(config_file);
fclose(config_file);
free(config_path);
for (size_t i = 1; i < (size_t)argc; ++i) { for (size_t i = 1; i < (size_t)argc; ++i) {
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) { if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) {
if (i == (size_t)argc - 1) { if (i == (size_t)argc - 1) {
@ -47,18 +59,6 @@ int main(int argc, char *argv[]) {
} }
} }
FILE *config_file = fopen(config_path, "r");
if (config_file == NULL) {
fprintf(stderr, "error: failed to open config at: %s\n", config_path);
exit(EXIT_FAILURE);
}
Config config = parse_config(config_file);
fclose(config_file);
free(config_path);
fetch(config); fetch(config);
return 0; return 0;