moving config parsing before option parsing
This commit is contained in:
parent
c50902e45e
commit
55414046ea
1 changed files with 12 additions and 12 deletions
24
src/main.c
24
src/main.c
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue