bootstrap/main.c

35 lines
848 B
C
Raw Normal View History

#include <stdio.h>
2023-11-22 20:43:34 +00:00
#include <stdlib.h>
#include "config.h"
2023-11-22 20:43:34 +00:00
#include "dyn_array.h"
2023-11-23 11:10:04 +00:00
const char *ENV_SPEC_ROOT_DIR = "SPEC_ROOT_DIR";
2023-11-22 18:15:12 +00:00
int main(int argc, char **argv) {
2023-11-22 20:43:34 +00:00
int num = 0;
if (argc != 2) {
fprintf(stderr, "Usage: gen-flake <spec>\n");
exit(EXIT_FAILURE);
}
2023-11-23 11:10:04 +00:00
const char *root_dir = getenv(ENV_SPEC_ROOT_DIR);
2023-11-23 14:40:17 +00:00
struct Config *config = 0;
switch (config_load(root_dir, argv[1], &config)) {
case ENV_SPEC_ROOT_DIR_MISSING:
fprintf(stderr, "Must specify $SPEC_ROOT_DIR environment variable.");
exit(EXIT_FAILURE);
case ENV_SPEC_ROOT_DIR_EMPTY:
fprintf(stderr, "$SPEC_ROOT_DIR environment variable should not be empty.");
exit(EXIT_FAILURE);
case INVALID_TARGET:
fprintf(stderr, "Target spec `%s` is invalid.", argv[1]);
exit(EXIT_FAILURE);
}
2023-11-22 18:15:12 +00:00
2023-11-23 14:40:17 +00:00
config_free(config);
return EXIT_SUCCESS;
2023-11-22 18:15:12 +00:00
}